Skip to content

Commit

Permalink
wip feat(dicom): run readOverlappingSegmentation for SEG
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Sep 25, 2024
1 parent fd0f7d0 commit 294f768
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/io/dicom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { runPipeline, TextStream, InterfaceTypes, Image } from 'itk-wasm';

import { readDicomTags, readImageDicomFileSeries } from '@itk-wasm/dicom';
import {
readDicomTags,
readImageDicomFileSeries,
readOverlappingSegmentation,
} from '@itk-wasm/dicom';

import itkConfig from '@/src/io/itk/itkConfig';
import { getDicomSeriesWorkerPool, getWorker } from '@/src/io/itk/worker';
Expand Down Expand Up @@ -176,13 +180,19 @@ export async function readVolumeSlice(
* @param {File[]} seriesFiles the set of files to build volume from
* @returns ItkImage
*/
export async function buildImage(seriesFiles: File[]) {
export async function buildImage(seriesFiles: File[], modality: string) {
const inputImages = seriesFiles.map((file) => sanitizeFile(file));
if (modality === 'SEG') {
const result = await readOverlappingSegmentation(inputImages[0], {
webWorker: getWorker(),
});
console.log(result.metaInfo);
return result.segImage;
}
const result = await readImageDicomFileSeries({
webWorkerPool: getDicomSeriesWorkerPool(),
inputImages,
singleSortedSeries: false,
});

return result.outputImage;
}
12 changes: 8 additions & 4 deletions src/store/datasets-dicom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ export const getWindowLevels = (info: VolumeInfo) => {
return widths.map((width, i) => ({ width, level: levels[i] }));
};

const constructImage = async (volumeKey: string) => {
const constructImage = async (volumeKey: string, volumeInfo: VolumeInfo) => {
const fileStore = useFileStore();
const files = fileStore.getFiles(volumeKey);
if (!files) throw new Error('No files for volume key');
const image = vtkITKHelper.convertItkToVtkImage(
await DICOM.buildImage(files)
await DICOM.buildImage(files, volumeInfo.Modality)
);
return image;
};
Expand Down Expand Up @@ -196,7 +196,11 @@ export const useDICOMStore = defineStore('dicom', {
Object.entries(volumeToFiles).map(async ([volumeKey, files]) => {
// Read tags of first file
if (!(volumeKey in this.volumeInfo)) {
const tags = await readDicomTags(files[0]);
const rawTags = await readDicomTags(files[0]);
// trim whitespace from all values
const tags = Object.fromEntries(
Object.entries(rawTags).map(([key, value]) => [key, value.trim()])
);
// TODO parse the raw string values
const patient = {
PatientID: tags.PatientID || ANONYMOUS_PATIENT_ID,
Expand Down Expand Up @@ -398,7 +402,7 @@ export const useDICOMStore = defineStore('dicom', {
: [];
// actually build volume or wait for existing build?
const newImagePromise = buildNeeded
? constructImage(volumeKey)
? constructImage(volumeKey, this.volumeInfo[volumeKey])
: this.volumeImageData[volumeKey];
// let other calls to buildVolume reuse this constructImage work
this.volumeImageData[volumeKey] = newImagePromise;
Expand Down

0 comments on commit 294f768

Please sign in to comment.