Thanks Riesmeier for replying. Yes it doesn't work for compressed images. I naively thought it was solved. Now, I'm trying to load a compressed multiframe dicom image, decompress it and get a Bit map image from the pixel that I get from the first frame.
The code is as below:
Code: Select all
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmimage/diregist.h"
#include "dcmtk/dcmjpeg/djencode.h"
#include "dcmtk/dcmjpeg/djdecode.h"
#include <mdfdsman.h>
#include <iostream>
#include <stdio.h> /* printf, fgets */
#include <stdlib.h>
using namespace std;
int main()
{
DJDecoderRegistration::registerCodecs();// register JPEG codecs
DcmFileFormat fileformat;
if (fileformat.loadFile("test.dcm").good())
{
DcmDataset *dataset = fileformat.getDataset();
OFCondition a=dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
if (dataset->canWriteXfer(EXS_LittleEndianExplicit))
{
a=dataset->loadAllDataIntoMemory();
DicomImage bmImg(dataset,dataset->getOriginalXfer());
Uint16 bitNum=0;
dataset->findAndGetUint16(DCM_BitsAllocated,bitNum);
int b=bmImg.writeBMP("testBmp.bmp",bitNum,1);// Trying to get the bitmap image from the first frame
// using the documentation mentioned in http://support.dcmtk.org/docs/classDicomImage.html#265cb0e6b974b2cd1b5544a6c22245ff
}
return 0;
}
}
But even though I do manage to decompress the image and even I can also store the pixel data of the first frame or any frame in a variable if I want I cannot produce that Bitmap image.
Code: Select all
bmImg.writeBMP("testBmp.bmp",bitNum,1);
is not working. Please suggest me what I could do?
I would also like to ask another question. I have already managed to modify the pixel data of a dicom image if it's a single frame via the following code:
Code: Select all
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmimage/diregist.h"
#include <mdfdsman.h>
#include <iostream>
#include <stdio.h> /* printf, fgets */
#include <stdlib.h>
using namespace std;
int main()
{
MdfDatasetManager FiLe;
if(EC_Normal==FiLe.loadFile("test1.dcm",ERM_autoDetect,EXS_Unknown))
{
FiLe.getDataset()->loadAllDataIntoMemory();
E_TransferSyntax xfer = FiLe.getDataset()->getOriginalXfer();
FiLe.getDataset()->chooseRepresentation(xfer, NULL);
int ymin=50;//minimum ros
int ymax=500;//maximum rows
int xmin=100;//Minimum columns
int xmax=600;//Maximum columns
const Uint8* pixelValues=0;
int index=0;
Uint16 rows = 0;
Uint16 cols = 0;
Uint16 samplePerPixel = 0;
Uint16 planarConfiguration = 0;
unsigned long * count=NULL;
const OFBool searchIntoSub=OFFalse;
OFCondition Cond=FiLe.getDataset()->findAndGetUint8Array(DCM_PixelData, pixelValues, count,searchIntoSub);
if(EC_Normal==FiLe.getDataset()->findAndGetUint16(DCM_Rows, rows))
{
if(EC_Normal==FiLe.getDataset()->findAndGetUint16(DCM_Columns, cols))
{
if(EC_Normal==FiLe.getDataset()->findAndGetUint16(DCM_SamplesPerPixel,samplePerPixel))
{
if(EC_Normal==FiLe.getDataset()->findAndGetUint16(DCM_PlanarConfiguration,planarConfiguration))
{
int count = (unsigned long)rows * cols * samplePerPixel;
Uint8 * newPixelValues = new Uint8[count];
Uint16 area=(unsigned long)rows * cols;
if(pixelValues != NULL)
{
for(unsigned long y = 0; y < rows; y++)
{
for(unsigned long x = 0; x < cols; x++)
{
if(x>xmin && x<xmax && y>ymin && y<ymax)
{
index=(x + y + y*(cols-1))*samplePerPixel;
newPixelValues[index] = 0;
newPixelValues[index + 1] = 0;
newPixelValues[index +2] = 0;
}
else
{
index=(x + y + y*(cols-1))*samplePerPixel;
newPixelValues[index] = pixelValues[index];
newPixelValues[index + 1] = pixelValues[index + 1];
newPixelValues[index + 2] = pixelValues[index + 2];
}
}
}
int a=0;
if(FiLe.getDataset()->putAndInsertUint8Array(DCM_PixelData, (const Uint8 *)newPixelValues, rows * cols * samplePerPixel,true) == EC_Normal)
{
DicomImage bmpImg(FiLe.getDataset(), FiLe.getDataset()->getOriginalXfer());
bmpImg.writeBMP("newImage.bmp");
if(EC_Normal==FiLe.saveFile("test1.dcm",EXS_Unknown,EET_UndefinedLength,EGL_recalcGL,EPD_noChange,0,0,OFFalse))
{
cout<<"File saved properly"<<endl;
}
else
{
cout<<"Error in program"<<endl;
}
}
}
newPixelValues=NULL;
delete newPixelValues;
}
}
}
}
pixelValues=NULL;
delete pixelValues;
}
return 0;
}
What change should I make for a multiframe image in that program? I mean it was very easy to take the pixel data using
Code: Select all
findAndGetUint8Array(DCM_PixelData, pixelValues, count,searchIntoSub)
and than modify it and insert it via
Code: Select all
putAndInsertUint8Array(DCM_PixelData, (const Uint8 *)newPixelValues, rows * cols * samplePerPixel,true)
but I can't see any option in
class that offers me to extract the pixel data using the frame index and also insert new modified pixel data using the frame index. So, how do you think I should adapt my program for Multiframe dicom images?
Thanks a lot for your attention.