【发布时间】:2015-03-04 16:03:46
【问题描述】:
我使用了medPhys-pl,solution jpg to dicom with dcm4che3提出的解决方案。
我尝试将文件 jpg 转换为文件 dicom。当 jpg 是单色时,我的代码是成功的,但是如果文件 jpg 是 RGB,则文件 dicom 的颜色与原始图像有关。
有人知道原因???
谢谢
File fileJpg = new File(path + "tmp_" + numImagen + ".jpg");
File fileDicomFinal = new File(path + "tmp_" + numImagen + ".dcm");
File fileDicomOrig = new File(cabeceraOriginal);
File fileDicomTipo = new File(cabeceraTipo);
BufferedImage jpg = ImageIO.read(fileJpg);
//Convert the image to a byte array
DataBufferByte buff = (DataBufferByte) jpg.getData().getDataBuffer();
byte[] buffbytes = buff.getData(0);
byte[] b = new byte[5*buff.getData(0).length];
for (int j = 0; j < 5; j++) {
System.arraycopy(buffbytes, 0, b, j*buffbytes.length, buffbytes.length);
}
//Copy a header
DicomInputStream dis = new DicomInputStream(fileDicomTipo);
Attributes meta = dis.readFileMetaInformation();
Attributes attribs = dis.readDataset(-1, Tag.PixelData);
dis.close();
DicomInputStream disOrig = new DicomInputStream(fileDicomOrig);
Attributes attribsOrig = disOrig.readDataset(-1, Tag.PixelData);
disOrig.close();
//get properties of image
int colorComponents = jpg.getColorModel().getNumColorComponents();
int bitsPerPixel = jpg.getColorModel().getPixelSize();
int bitsAllocated = (bitsPerPixel / colorComponents);
int samplesPerPixel = colorComponents;
//Change the rows and columns
attribs.setString(Tag.SpecificCharacterSet, VR.CS, "ISO_IR 100");
attribs.setString(Tag.PhotometricInterpretation, VR.CS, samplesPerPixel == 3 ? "RGB" : "MONOCHROME2");
attribs.setInt(Tag.SamplesPerPixel, VR.US, samplesPerPixel);
attribs.setInt(Tag.Rows, VR.US, jpg.getHeight());
attribs.setInt(Tag.Columns, VR.US, jpg.getWidth());
attribs.setInt(Tag.BitsAllocated, VR.US, bitsAllocated);
attribs.setInt(Tag.BitsStored, VR.US, bitsAllocated);
attribs.setInt(Tag.HighBit, VR.US, bitsAllocated-1);
attribs.setInt(Tag.PixelRepresentation, VR.US, 0);
/*Also, our Dicom header needs information about date and time of creation:*/
attribs.setDate(Tag.InstanceCreationDate, VR.DA, new Date());
attribs.setDate(Tag.InstanceCreationTime, VR.TM, new Date());
/* Every Dicom file has a unique identifier.
* Here we’re generating study, series and Sop instances UIDs.
* You may want to modify these values, but you should to care about their uniqueness.
*/
attribs.setString(Tag.SeriesInstanceUID, VR.UI, UIDUtils.createUID();
attribs.setString(Tag.SOPInstanceUID, VR.UI, UIDUtils.createUID());
attribs.setString(Tag.StudyInstanceUID, VR.UI, UIDUtils.createUID());
attribs.setString(Tag.AccessionNumber, VR.IS, attribsOrig.getString(Tag.AccessionNumber));
attribs.setString(Tag.PatientName, VR.CS, attribsOrig.getString(Tag.PatientName));
attribs.setString(Tag.InstitutionName, VR.CS, attribsOrig.getString(Tag.InstitutionName));
attribs.setString(Tag.PatientID, VR.CS, attribsOrig.getString(Tag.PatientID));
attribs.setString(Tag.PatientBirthDate, VR.DT, attribsOrig.getString(Tag.PatientBirthDate));
attribs.setString(Tag.PatientSex, VR.CS, attribsOrig.getString(Tag.PatientSex));
attribs.setString(Tag.OtherPatientIDs, VR.CS, attribsOrig.getString(Tag.OtherPatientIDs));
attribs.setString(Tag.PatientAge, VR.AS, attribsOrig.getString(Tag.PatientAge));
attribs.setString(Tag.AcquisitionDateTime, VR.DT, attribsOrig.getString(Tag.AcquisitionDateTime));
attribs.setString(Tag.AcquisitionDate, VR.DT, attribsOrig.getString(Tag.AcquisitionDate));
attribs.setString(Tag.AcquisitionTime, VR.DT, attribsOrig.getString(Tag.AcquisitionTime));
attribs.setString(Tag.StudyInstanceUID , VR.UI, attribsOrig.getString(Tag.StudyInstanceUID));
//Write the file
attribs.setBytes(Tag.PixelData, VR.OW, b);
DicomOutputStream dcmo = new DicomOutputStream(fileDicomFinal);
dcmo.writeFileMetaInformation(meta);
attribs.writeTo(dcmo);
dcmo.close();
【问题讨论】:
-
你试过什么?已单步执行您的代码并尝试查看发生了什么变化?
-
我尝试将文件 jpg 转换为文件 dicom。当 jpg 是单色时,我的代码是成功的,但是如果文件 jpg 是 RGB,则文件 dicom 的颜色已更改为原始图像。
-
你的 jpeg 来自哪里?您是否安装了 jai imageio 编解码器,或者您是否使用 jre 中的 jpeg 编解码器?愤怒中的 jpeg 图像写入器存在某些类型的元数据的缺陷,可能会破坏颜色:bugs.java.com/bugdatabase/view_bug.do?bug_id=6243376
-
我不明白你的第一个问题。 “你的 jpeg 是从哪里来的?”我已经安装了: jai-1_1_3-lib-windows-i586.exe jai-1_1_3-lib-windows-i586-jdk.exe 和 jai-1_1_3-lib-windows-i586-jre.exe 也许我读错了图片方式?
-
我不旋转图片,我上传了一个样本:jpg original s30.postimg.org/4wh0va3w1/temp.jpg and capture of dicom s30.postimg.org/xamgf5rg1/dicom.jpg