-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dcm4che tool (uft8 converter, dcm2jpg)
- Loading branch information
1 parent
ad1f4d1
commit 730e0c0
Showing
2,086 changed files
with
188,809 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dcm filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const _ = require("lodash"); | ||
const fs = require("fs"); | ||
const { java } = require("./java-instance"); | ||
const { File } = require("./wrapper/java/io/File"); | ||
const { Dcm2Jpg } = require("./wrapper/org/dcm4che3/tool/dcm2jpg/Dcm2Jpg"); | ||
const { createDcm2Jpg$ReadImageProxy } = require("./wrapper/org/dcm4che3/tool/dcm2jpg/Dcm2Jpg$ReadImage"); | ||
const { ICCProfile$Option } = require("./wrapper/org/dcm4che3/image/ICCProfile$Option"); | ||
const { Float } = require("./wrapper/java/lang/Float"); | ||
|
||
/** | ||
* @typedef Dcm2JpgOptions | ||
* @property {string} dicomFile | ||
* @property {string} jpgFile | ||
* @property {string} iccProfileName | ||
* @property {number} frameNumber | ||
* @property {number} jpgQuality | ||
* @property {number} windowCenter | ||
* @property {number} windowWidth | ||
* @property {string} format | ||
*/ | ||
|
||
|
||
class JsDcm2Jpeg { | ||
|
||
/** @type {Dcm2JpgOptions} */ | ||
static defaultOptions={ format: "JPEG", jpgQuality: 0.9, frameNumber: 1 }; | ||
|
||
/** | ||
* | ||
* @param {Dcm2JpgOptions} options | ||
*/ | ||
constructor(options = { format: "JPEG", jpgQuality: 0.9, frameNumber: 1 }) { | ||
/** @type {Dcm2Jpg} */ | ||
this.dcm2jpg; | ||
|
||
this.options = options; | ||
} | ||
|
||
async init() { | ||
this.dcm2jpg = await Dcm2Jpg.newInstanceAsync(); | ||
|
||
const readImageProxy = createDcm2Jpg$ReadImageProxy({ | ||
apply: (file) => { | ||
return this.dcm2jpg.readImageFromDicomInputStreamSync(file); | ||
} | ||
}, { | ||
keepAsDaemon: true | ||
}); | ||
|
||
await this.dcm2jpg.setReadImage(readImageProxy); | ||
await this.dcm2jpg.setICCProfile(await ICCProfile$Option.valueOf("no")); | ||
await this.dcm2jpg.setFrame(this.options.frameNumber); | ||
|
||
await this.initSetWindowCenter(); | ||
await this.initSetWindowWidth(); | ||
|
||
await this.dcm2jpg.initImageWriter(this.options.format, | ||
null, | ||
"com.sun.imageio.plugins.*", | ||
null, | ||
await Float.newInstanceAsync(this.options.jpgQuality) | ||
); | ||
|
||
readImageProxy.reset(); | ||
|
||
return this; | ||
} | ||
|
||
async convert(src, dest) { | ||
|
||
if (_.isString(src)) { | ||
src = await File.newInstanceAsync(src); | ||
} | ||
|
||
if (_.isString(dest)) { | ||
dest = await File.newInstanceAsync(dest); | ||
} | ||
|
||
await this.dcm2jpg.convert(src, dest); | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
async initSetWindowWidth() { | ||
if (this.options.windowWidth) { | ||
await this.dcm2jpg.setWindowWidth(this.options.windowWidth); | ||
} | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
async initSetWindowCenter() { | ||
if (this.options.windowCenter) { | ||
await this.dcm2jpg.setWindowCenter(this.options.windowCenter); | ||
} | ||
} | ||
|
||
async getFrameImage(imagesPath , frameNumber) { | ||
let jpegFile = imagesPath.replace(/\.dcm\b/gi , `.${frameNumber-1}.jpg`); | ||
|
||
try { | ||
await this.dcm2jpg.setFrame(frameNumber); | ||
|
||
await this.convert(imagesPath, jpegFile); | ||
|
||
let rs = fs.createReadStream(jpegFile); | ||
return { | ||
status : true , | ||
imageStream : rs, | ||
imagePath: jpegFile | ||
}; | ||
} catch(e) { | ||
console.error(e); | ||
return { | ||
status : false , | ||
imageStream : e, | ||
imagePath: jpegFile | ||
}; | ||
} | ||
} | ||
} | ||
|
||
module.exports.JsDcm2Jpeg = JsDcm2Jpeg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { java } = require("./java-instance"); | ||
const { File } = require("./wrapper/java/io/File"); | ||
const { ElementDictionary } = require("./wrapper/org/dcm4che3/data/ElementDictionary"); | ||
const { Tag } = require("./wrapper/org/dcm4che3/data/Tag"); | ||
const { Attributes } = require("./wrapper/org/dcm4che3/data/Attributes"); | ||
const { DicomInputStream } = require("./wrapper/org/dcm4che3/io/DicomInputStream"); | ||
const { DicomOutputStream } = require("./wrapper/org/dcm4che3/io/DicomOutputStream"); | ||
const { SafeClose } = require("./wrapper/org/dcm4che3/util/SafeClose"); | ||
|
||
|
||
class DicomUtf8Converter { | ||
constructor(filename, outputFilename = "") { | ||
this.filename = filename; | ||
this.outputFilename = outputFilename; | ||
if (!outputFilename) this.outputFilename = this.filename; | ||
|
||
/** @type {Attributes} */ | ||
this.attributes; | ||
/** @type {Attributes} */ | ||
this.fileMetaInfo; | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
async readDicomFile() { | ||
let file = await File.newInstanceAsync(this.filename); | ||
|
||
/** @type {DicomInputStream} */ | ||
let dicomInputStream; | ||
try { | ||
|
||
dicomInputStream = await DicomInputStream.newInstanceAsync(file); | ||
|
||
this.attributes = await dicomInputStream.readDataset(); | ||
|
||
this.fileMetaInfo = await dicomInputStream.readFileMetaInformation(); | ||
this.fileMetaInfo = await this.attributes.createFileMetaInformation(await dicomInputStream.getTransferSyntax()); | ||
} finally { | ||
dicomInputStream.closeSync(); | ||
} | ||
} | ||
|
||
async convert() { | ||
await this.readDicomFile(); | ||
|
||
await this.attributes.setString(Tag.SpecificCharacterSet, ElementDictionary.vrOfSync(Tag.SpecificCharacterSet, ""), "ISO_IR 192"); | ||
|
||
let outputFile = new File(this.outputFilename); | ||
|
||
/** @type {DicomOutputStream} */ | ||
let dicomOutputStream; | ||
try { | ||
dicomOutputStream = await DicomOutputStream.newInstanceAsync(outputFile); | ||
await dicomOutputStream.writeDataset(this.fileMetaInfo, this.attributes); | ||
} finally { | ||
SafeClose.closeSync(dicomOutputStream); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports.DicomUtf8Converter = DicomUtf8Converter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const java = require('java-bridge'); | ||
const glob = require("glob"); | ||
const path = require("path"); | ||
|
||
java.ensureJvm(); | ||
|
||
let jarFiles = glob.sync("**/*.jar", { | ||
cwd: path.join(__dirname, "./javaNode"), | ||
absolute: true | ||
}); | ||
|
||
java.appendClasspath(jarFiles); | ||
|
||
module.exports.java = java; |
Binary file added
BIN
+67.9 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/clibwrapper_jiio-1.2-pre-dr-b04.jar
Binary file not shown.
Binary file added
BIN
+52.6 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/commons-cli-1.4.jar
Binary file not shown.
Binary file added
BIN
+504 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-core-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+70.7 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-image-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+129 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-imageio-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+38.3 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-imageio-opencv-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+8.8 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-imageio-rle-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+197 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-net-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+20.9 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-tool-common-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+12.7 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/dcm4che-tool-dcm2jpg-5.27.0.jar
Binary file not shown.
Binary file added
BIN
+1.12 MB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/jai_imageio-1.2-pre-dr-b04.jar
Binary file not shown.
Binary file added
BIN
+228 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/logback-classic-1.2.9.jar
Binary file not shown.
Binary file added
BIN
+444 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/logback-core-1.2.9.jar
Binary file not shown.
Binary file added
BIN
+40.5 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/slf4j-api-1.7.32.jar
Binary file not shown.
Binary file added
BIN
+207 KB
models/DICOM/dcm4che/javaNode/dcm4chee-5.27.0/lib/weasis-core-img-4.5.5.jar
Binary file not shown.
Oops, something went wrong.