Skip to content

Commit

Permalink
fix: wado-uri not apply window level of image
Browse files Browse the repository at this point in the history
# Problems
- The image not apply window level (window center and window width)
, when image have both of them
- `getFrameImage` not support regenerate image when apply window level

# Solutions
- Get image's window level first, if exist call dcmj2pnm with `+Ww`
to set window
- If `otherOptions` present (e.g. window level), regenerate image
  • Loading branch information
Chinlinlee committed Apr 27, 2023
1 parent 0eae01f commit 5de5e19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
48 changes: 29 additions & 19 deletions api/dicom/controller/wado.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,37 @@ async function handleFrameNumber (param , res , dicomFile) {
let images = path.join(process.env.DICOM_STORE_ROOTPATH, imageRelativePath);
let jpegFile = images.replace(/\.dcm\b/gi , `.${param.frameNumber-1}.jpg`);
let finalJpegFile = "";
if(fs.existsSync(jpegFile)) {
finalJpegFile = jpegFile;
} else {
let dicomJson = await getDICOMJson(param);
let transferSyntax = _.get(dicomJson ,"00020010.Value.0");
if (!dcmtkSupportTransferSyntax.includes(transferSyntax)) {
let pythonDICOM2JPEGStatus = await getJpeg[process.env.ENV]['getJpegByPydicom'](images);
if (pythonDICOM2JPEGStatus) {
return fs.createReadStream(jpegFile).pipe(res);
}
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendServerWrongMessage(res , `can't not convert dicom to jpeg with transfer syntax: ${transferSyntax}`);
}
let frame = await getFrameImage(imageRelativePath, param.frameNumber);
if (frame.status) {
finalJpegFile = frame.imagePath;
} else {
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendServerWrongMessage(res , `dcmtk Convert frame error ${frame.imageStream}`);

let dicomJson = await getDICOMJson(param);
let transferSyntax = _.get(dicomJson ,"00020010.Value.0");
if (!dcmtkSupportTransferSyntax.includes(transferSyntax)) {
let pythonDICOM2JPEGStatus = await getJpeg[process.env.ENV]['getJpegByPydicom'](images);
if (pythonDICOM2JPEGStatus) {
return fs.createReadStream(jpegFile).pipe(res);
}
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendServerWrongMessage(res , `can't not convert dicom to jpeg with transfer syntax: ${transferSyntax}`);
}

let windowCenter = _.get(dicomJson, "00281050.Value.0");
let windowWidth = _.get(dicomJson, "00281051.Value.0");
let frame;
if (windowCenter && windowWidth) {
frame = await getFrameImage(imageRelativePath, param.frameNumber, [
"+Ww",
windowCenter,
windowWidth
]);
} else {
frame = await getFrameImage(imageRelativePath, param.frameNumber);
}
if (frame.status) {
finalJpegFile = frame.imagePath;
} else {
res.set('content-type' , 'application/json');
return dicomWebHandleError.sendServerWrongMessage(res , `dcmtk Convert frame error ${frame.imageStream}`);
}

let imageSharp = sharp(finalJpegFile);
let magick = new Magick(finalJpegFile);
handleImageQuality(param, magick);
Expand Down
2 changes: 1 addition & 1 deletion models/dcmtk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async function getFrameImage(imagesPath, frameNumber, otherOptions = []) {
let execCmd = "";
let images = path.join(process.env.DICOM_STORE_ROOTPATH, imagesPath);
let jpegFile = images.replace(/\.dcm\b/gi, `.${frameNumber - 1}.jpg`);
if (fs.existsSync(jpegFile)) {
if (fs.existsSync(jpegFile) && otherOptions.length == 0) {
let rs = fs.createReadStream(jpegFile);
return {
status: true,
Expand Down

0 comments on commit 5de5e19

Please sign in to comment.