同步遮盖影像初步预提交

Test_IRC_Net10
hang 2026-04-21 09:25:39 +08:00
parent 5e04634837
commit 152c5200cb
5 changed files with 77 additions and 11 deletions

View File

@ -178,11 +178,10 @@ public static class DicomPixelMasker
public static async Task<MemoryStream> MaskAsync(
Stream input,
IEnumerable<MaskRegion> regions,
DicomMaskOptions? options = null,
CancellationToken cancellationToken = default)
DicomMaskOptions? options = null)
{
var output = new MemoryStream();
await MaskAsync(input, output, regions, options, cancellationToken).ConfigureAwait(false);
await MaskAsync(input, output, regions, options).ConfigureAwait(false);
output.Position = 0;
return output;
}
@ -211,6 +210,7 @@ public static class DicomPixelMasker
var workingDataset = workingFile.Dataset;
var originalPhotometric = originalDataset.GetSingleValueOrDefault(DicomTag.PhotometricInterpretation, string.Empty);
Console.WriteLine($"Original Photometric={originalPhotometric}, Original TS={originalTs.UID.UID}");
var rows = workingDataset.GetSingleValue<int>(DicomTag.Rows);

View File

@ -2965,6 +2965,12 @@
<param name="inQuery"></param>
<returns></returns>
</member>
<member name="M:IRaCIS.Core.Application.Service.ImageAndDoc.StudyService.StudyMaskImage(IRaCIS.Core.Application.Contracts.StudyMaskImageCommand)">
<summary>
标注遮盖影像
</summary>
<returns></returns>
</member>
<member name="M:IRaCIS.Core.Application.Service.ImageAndDoc.StudyService.Preview(System.Guid)">
<summary> 指定资源Id渲染Dicom检查的Jpeg预览图像 </summary>
<param name="studyId"> Dicom检查的Id </param>

View File

@ -1,4 +1,5 @@
using FellowOakDicom;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.Service.ImageAndDoc.DTO;
using IRaCIS.Core.Domain.Share;
using Newtonsoft.Json;
@ -963,7 +964,7 @@ namespace IRaCIS.Core.Application.Contracts
}
public class SubjectVisitMarkQuery:PageInput
public class SubjectVisitMarkQuery : PageInput
{
public Guid TrialId { get; set; }
@ -1047,4 +1048,15 @@ namespace IRaCIS.Core.Application.Contracts
public List<StudyBasicInfo> UploadStudyList { get; set; }
}
public class StudyMaskImageCommand
{
public Guid? SeriesId { get; set; }
public List<Guid>? InstanceIdList { get; set; }
public List<MaskRegion> MaskRegionList { get; set; }
}
}

View File

@ -7,6 +7,7 @@ using IRaCIS.Core.Infrastructure;
using Medallion.Threading;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Drawing;
using ZiggyCreatures.Caching.Fusion;
namespace IRaCIS.Core.Application.Service.ImageAndDoc
@ -25,7 +26,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
IRepository<StudyMonitor> _studyMonitorRepository,
IRepository<SystemAnonymization> _systemAnonymizationRepository,
IRepository<NoneDicomStudy> _noneDicomStudyRepository,
IDistributedLockProvider _distributedLockProvider,
IDistributedLockProvider _distributedLockProvider, IOSSService _oSSService,
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IFusionCache _fusionCache) : BaseService, IStudyService
{
@ -66,6 +67,53 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
}
/// <summary>
/// 标注遮盖影像
/// </summary>
/// <returns></returns>
public async Task<IResponseOutput> StudyMaskImage(StudyMaskImageCommand inCommand)
{
if (inCommand.SeriesId == null && inCommand.InstanceIdList == null)
{
return ResponseOutput.NotOk("SeriesId and InstanceIdList can not both be null");
}
var instancePathList = new List<string>();
if (inCommand.SeriesId == null && inCommand.InstanceIdList != null)
{
instancePathList = await _dicomInstanceRepository.Where(t => inCommand.InstanceIdList.Contains(t.Id)).Select(t => t.Path).ToListAsync();
}
else
{
instancePathList = await _dicomInstanceRepository.Where(t => t.SeriesId == inCommand.SeriesId).Select(t => t.Path).ToListAsync();
}
foreach (var path in instancePathList)
{
try
{
var inputStream = await _oSSService.GetStreamFromOSSAsync(path);
var outPutStream = await DicomPixelMasker.MaskAsync(inputStream, inCommand.MaskRegionList);
var prefix = path.Substring(1, path.LastIndexOf('/') - 1);
await _oSSService.UploadToOSSAsync(outPutStream, prefix, $"MaskImage_{Path.GetFileName(path)}");
}
catch (Exception ex)
{
Log.Logger.Error(ex, $"StudyMaskImage Error for InstanceIdList Path:{path} {ex.Message}");
}
}
return ResponseOutput.Ok();
}
[TrialGlobalLimit("AfterStopCannNotOpt")]
public async Task<IResponseOutput> PreArchiveDicomStudy(PreArchiveDicomStudyCommand preArchiveStudyCommand)
@ -324,7 +372,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
}
var @lock2 = _distributedLockProvider.CreateLock($"StudyCommit");
@ -334,7 +382,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
await _dicomInstanceRepository.SaveChangesAsync();
}
await _fileUploadRecordRepository.BatchUpdateNoTrackingAsync(t => t.UploadBatchId == incommand.UploadBatchId, u => new FileUploadRecord() { StudyCode = findStudy.StudyCode });
await _fileUploadRecordRepository.BatchUpdateNoTrackingAsync(t => t.UploadBatchId == incommand.UploadBatchId, u => new FileUploadRecord() { StudyCode = findStudy.StudyCode });
}
catch (Exception ex)
{
@ -437,7 +485,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
Id = t.Id,
Bodypart = t.BodyPart,
BodyPartForEditOther=t.BodyPartForEditOther,
BodyPartForEditOther = t.BodyPartForEditOther,
Modalities = t.Modality,

View File

@ -129,8 +129,8 @@ namespace IRaCIS.Core.Application.Service
public async Task<IResponseOutput> MaskImage()
{
var sourceDir = @"D:\images";
var targetDir = @"D:\images\after";
var sourceDir = @"D:\images\11\像素匿名\隐私信息2&测量值\08\08017\基线V1\ST01371_1970-01-01_US\IMAGE";
var targetDir = @"D:\images\11\像素匿名\隐私信息2&测量值\08\08017\基线V1\ST01371_1970-01-01_US\IMAGE\after";
Directory.CreateDirectory(targetDir);
var regions = new[]
@ -138,7 +138,7 @@ namespace IRaCIS.Core.Application.Service
new MaskRegion(0, 0, 200, 200)
};
foreach (var inputPath in Directory.EnumerateFiles(sourceDir, "*.dcm", SearchOption.TopDirectoryOnly))
foreach (var inputPath in Directory.EnumerateFiles(sourceDir, "IM_*", SearchOption.TopDirectoryOnly))
{
var relativePath = Path.GetRelativePath(sourceDir, inputPath);
var outputPath = Path.Combine(targetDir, relativePath);