生成黑色图修改提交
parent
21136f1238
commit
875281adef
|
|
@ -16319,7 +16319,7 @@
|
|||
像素间距 (0028,0030)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.TestService.GenerateNoisePixel(FellowOakDicom.DicomDataset,System.String)">
|
||||
<member name="M:IRaCIS.Core.Application.Service.TestService.GenerateNoisePixel(FellowOakDicom.DicomDataset,System.String,System.Int32)">
|
||||
<summary>
|
||||
生成随机噪声图
|
||||
</summary>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Aliyun.OSS;
|
||||
using ClosedXML.Excel;
|
||||
using DocumentFormat.OpenXml.Presentation;
|
||||
using FellowOakDicom;
|
||||
using FellowOakDicom.Imaging;
|
||||
using FellowOakDicom.IO.Buffer;
|
||||
|
|
@ -495,19 +496,19 @@ namespace IRaCIS.Core.Application.Service
|
|||
var list = new List<GenerateIamgeInfo>();
|
||||
|
||||
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\CT.dcm", @"C:\work\测量图像\output", "CT", 20, list);
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\CT.dcm", @"C:\work\测量图像\output", "CT", 18, list);
|
||||
|
||||
|
||||
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\MR.dcm", @"C:\work\测量图像\output", "MR", 20, list);
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\MR.dcm", @"C:\work\测量图像\output", "MR", 18, list);
|
||||
|
||||
|
||||
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\PT.dcm", @"C:\work\测量图像\output", "PT", 10, list);
|
||||
await GenerateAsync(@"C:\work\测量图像\纯黑色\PT.dcm", @"C:\work\测量图像\output", "PT", 9, list);
|
||||
|
||||
|
||||
string exportPath = @$"C:\work\测量图像\outPut.xlsx";
|
||||
MiniExcel.SaveAs(exportPath, list,overwriteFile:true);
|
||||
MiniExcel.SaveAs(exportPath, list, overwriteFile: true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
|
@ -518,6 +519,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
public class GenerateIamgeInfo
|
||||
{
|
||||
|
||||
public string FileName { get; set; }
|
||||
/// <summary>
|
||||
/// 患者ID (0010,0020)
|
||||
/// </summary>
|
||||
|
|
@ -586,7 +589,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
/// </summary>
|
||||
private MaskRegion GenerateNoisePixel(
|
||||
DicomDataset ds,
|
||||
string modality)
|
||||
string modality, int index)
|
||||
{
|
||||
Random random = new Random(); // 创建实例
|
||||
|
||||
|
|
@ -619,11 +622,77 @@ namespace IRaCIS.Core.Application.Service
|
|||
// PixelSpacing
|
||||
double pixelSpacing = 0.5;
|
||||
|
||||
double widthMm = 0;
|
||||
double heightMm = 0;
|
||||
|
||||
// 生成10cm-20cm矩形
|
||||
|
||||
double widthMm = random.Next(100, 200);
|
||||
if (modality == "CT")
|
||||
{
|
||||
if (index <= 6)
|
||||
{
|
||||
widthMm = random.Next(10, 20);
|
||||
|
||||
heightMm = random.Next(10, 20);
|
||||
}
|
||||
else if (index > 6 && index <= 12)
|
||||
{
|
||||
widthMm = random.Next(40, 60);
|
||||
|
||||
heightMm = random.Next(40, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
widthMm = random.Next(100, 150);
|
||||
|
||||
heightMm = random.Next(100, 150);
|
||||
}
|
||||
}
|
||||
|
||||
if (modality == "MR")
|
||||
{
|
||||
if (index <= 6)
|
||||
{
|
||||
widthMm = random.Next(10, 20);
|
||||
|
||||
heightMm = random.Next(10, 20);
|
||||
}
|
||||
else if (index > 6 && index <= 12)
|
||||
{
|
||||
widthMm = random.Next(40, 60);
|
||||
|
||||
heightMm = random.Next(40, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
widthMm = random.Next(100, 150);
|
||||
|
||||
heightMm = random.Next(100, 150);
|
||||
}
|
||||
}
|
||||
|
||||
if (modality == "PT")
|
||||
{
|
||||
if (index <= 3)
|
||||
{
|
||||
widthMm = random.Next(10, 20);
|
||||
|
||||
heightMm = random.Next(10, 20);
|
||||
}
|
||||
else if (index > 3 && index <= 6)
|
||||
{
|
||||
widthMm = random.Next(40, 60);
|
||||
|
||||
heightMm = random.Next(40, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
widthMm = random.Next(100, 150);
|
||||
|
||||
heightMm = random.Next(100, 150);
|
||||
}
|
||||
}
|
||||
|
||||
double heightMm = random.Next(100, 200);
|
||||
|
||||
|
||||
|
||||
|
|
@ -631,9 +700,9 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
int height = (int)(heightMm / pixelSpacing);
|
||||
|
||||
int x = random.Next(0, cols - width);
|
||||
int x = random.Next(20, cols - width - 20);
|
||||
|
||||
int y = random.Next(0, rows - height);
|
||||
int y = random.Next(20, rows - height - 20);
|
||||
|
||||
int min;
|
||||
int max;
|
||||
|
|
@ -740,29 +809,35 @@ namespace IRaCIS.Core.Application.Service
|
|||
Directory.CreateDirectory(outputDir);
|
||||
|
||||
|
||||
//
|
||||
// Series UID
|
||||
//
|
||||
string seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;
|
||||
var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// SeriesNumber
|
||||
//
|
||||
int seriesNumber = random.Next(1, 101);
|
||||
var seriesNumbers = Enumerable.Range(1, 101)
|
||||
.OrderBy(x => random.Next())
|
||||
.Take(count)
|
||||
.ToList().OrderBy(t=>t).ToList();
|
||||
|
||||
|
||||
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
|
||||
//
|
||||
// Series UID
|
||||
//
|
||||
string seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;
|
||||
|
||||
//
|
||||
// SeriesNumber
|
||||
//
|
||||
int seriesNumber = seriesNumbers[i - 1];
|
||||
|
||||
var file = await DicomFile.OpenAsync(template);
|
||||
|
||||
|
||||
var ds = file.Dataset;
|
||||
|
||||
|
||||
ds.AddOrUpdate(DicomTag.StudyInstanceUID, studyUid);
|
||||
|
||||
|
||||
//
|
||||
|
|
@ -773,14 +848,14 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
ds.AddOrUpdate(DicomTag.SeriesNumber, seriesNumber);
|
||||
|
||||
ds.AddOrUpdate(DicomTag.InstanceNumber, i);
|
||||
ds.AddOrUpdate(DicomTag.InstanceNumber, 1);
|
||||
|
||||
|
||||
if (modality == "CT")
|
||||
{
|
||||
ds.AddOrUpdate(DicomTag.SliceLocation, (i * 5).ToString());
|
||||
ds.AddOrUpdate(DicomTag.RescaleSlope, "1");
|
||||
ds.AddOrUpdate(DicomTag.RescaleIntercept, "-1024");
|
||||
//ds.AddOrUpdate(DicomTag.RescaleIntercept, "-1024");
|
||||
}
|
||||
|
||||
if (modality == "PT")
|
||||
|
|
@ -797,8 +872,9 @@ namespace IRaCIS.Core.Application.Service
|
|||
ds.AddOrUpdate(DicomTag.PatientWeight, weight.ToString("F1"));
|
||||
}
|
||||
|
||||
var seriesDescription = $"{modality} Data";
|
||||
var seriesDescription = $"{modality} Data {seriesNumber}";
|
||||
ds.AddOrUpdate(DicomTag.SeriesDescription, seriesDescription);
|
||||
ds.AddOrUpdate(DicomTag.StudyDescription, seriesDescription);
|
||||
|
||||
|
||||
var sopUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;
|
||||
|
|
@ -824,7 +900,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
// 生成麻子PixelData
|
||||
//
|
||||
|
||||
var region = GenerateNoisePixel(ds, modality);
|
||||
var region = GenerateNoisePixel(ds, modality, i);
|
||||
|
||||
|
||||
|
||||
|
|
@ -837,16 +913,17 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
await file.SaveAsync(fileName);
|
||||
|
||||
var studyUid = ds.GetSingleValueOrDefault(DicomTag.StudyInstanceUID, string.Empty);
|
||||
var sUid = ds.GetSingleValueOrDefault(DicomTag.StudyInstanceUID, string.Empty);
|
||||
var pid = ds.GetSingleValueOrDefault(DicomTag.PatientID, string.Empty);
|
||||
var pName = ds.GetSingleValueOrDefault(DicomTag.PatientName, string.Empty);
|
||||
|
||||
generateIamgeInfos.Add(new GenerateIamgeInfo()
|
||||
{
|
||||
FileName = Path.GetFileName(fileName),
|
||||
// 初始化默认值
|
||||
PatientId = pid,
|
||||
PatientName = pName,
|
||||
StudyInstanceUID = studyUid,
|
||||
StudyInstanceUID = sUid,
|
||||
SeriesInstanceUID = seriesUid,
|
||||
SOPInstanceUID = sopUid,
|
||||
SeriesDescription = seriesDescription,
|
||||
|
|
|
|||
Loading…
Reference in New Issue