All other questions regarding DCMTK
Moderator: Moderator Team
martinrame
Posts: 348 Joined: Mon, 2009-02-23, 19:57
#1
Post
by martinrame » Mon, 2011-03-21, 20:56
Hi, I would like to replace part of an image with my own pixel data, to anonymize it, for example.
I created the following code after reading many posts on the forum, but it doesn't work.
What I'm doing wrong?.
Code: Select all
/* lDataset is a DcmDataset already in memory */
const Uint8 * pixelData = NULL;
unsigned long pcount;
lDataset->findAndGetUint8Array(DCM_PixelData, pixelData, &pcount);
if(pixelData != NULL)
{
for(unsigned long j = 0; j<pcount; j++)
{
pixelData = (Uint8 *)0;
pixelData++;
}
if(lDataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pcount) == EC_Normal)
{
DicomImage lNewImg(lDataset, lDataset->getOriginalXfer());
lNewImg.writeBMP("output.bmp");
}
}
Jörg Riesmeier
ICSMED DICOM Services
Posts: 2217 Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany
#2
Post
by Jörg Riesmeier » Tue, 2011-03-22, 11:03
I'm sorry but more details would be needed in order to help you. E.g. what does "but it doesn't work" mean? Are the pixel data really stored with VR=OB (uncompressed)?
And, btw, "pixelData = (Uint8 *)0;" is probably not what you want: Setting the pixelData pointer to "0" (NULL) and then adding 1 to the address
martinrame
Posts: 348 Joined: Mon, 2009-02-23, 19:57
#3
Post
by martinrame » Tue, 2011-03-22, 13:13
Let me update the code a litle to show what I need:
Code: Select all
/* lDataset is a DcmDataset already in memory */
const Uint8 * pixelData = NULL;
unsigned long pcount;
lDataset->findAndGetUint8Array(DCM_PixelData, pixelData, &pcount);
if(pixelData != NULL)
{
Uint8 * myPixelData[pcount];
for(unsigned long j = 0; j<pcount; j++)
{
mypixelData = 0;
}
if(lDataset->putAndInsertUint8Array(DCM_PixelData, (const Uint8 *) mypixelData, pcount) == EC_Normal)
{
DicomImage lNewImg(lDataset, lDataset->getOriginalXfer());
lNewImg.writeBMP("output.bmp");
}
}
What I want to do is to change the data contained in pixelData, but I get an exception on mypixelData = 0;
Michael Onken
DCMTK Developer
Posts: 2073 Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:
#4
Post
by Michael Onken » Tue, 2011-03-22, 14:02
Hi,
What I want to do is to change the data contained in pixelData, but I get an exception on mypixelData = 0;
Well, you set it to 0, at least the first pixel cell, j-times!
Code: Select all
for(unsigned long j = 0; j<pcount; j++)
{
mypixelData = 0;
}
Do you want to do instead
Code: Select all
for(unsigned long j = 0; j<pcount; j++)
{
mypixelData[j] = 0;
}
to set every pixel cell to the value 0? If so, there would be faster methods,e.g. with
memset .
Michael
martinrame
Posts: 348 Joined: Mon, 2009-02-23, 19:57
#5
Post
by martinrame » Tue, 2011-03-22, 16:29
Finally I found what I wanted:
Code: Select all
const Uint16 * pixelData = NULL;
Uint16 lRows = 0;
Uint16 lCols = 0;
DcmDataset * lDataset = fileFormat->getDataset();
lDataset->findAndGetUint16Array(DCM_PixelData, pixelData);
lDataset->findAndGetUint16(DCM_Rows, lRows);
lDataset->findAndGetUint16(DCM_Columns, lCols);
int lCount = (unsigned long)lRows * lCols;
Uint16 * mypixelData = new Uint16[lCount];
if(pixelData != NULL)
{
for(unsigned long x = 0; x < lCols; x++)
{
for(unsigned long y = 0; y < lRows; y++)
{
if(((y > 20) && (y < 100)) && ((x > 20) && (x < 1000)))
{
mypixelData[x + y * lCols] = 0;
}
else
mypixelData[x + y * lCols] = pixelData[x + y * lCols];
}
}
if(lDataset->putAndInsertUint16Array(DCM_PixelData, (const Uint16 *)mypixelData, lRows * lCols) == EC_Normal)
{
DicomImage lNewImg(lDataset, lDataset->getOriginalXfer());
lNewImg.writeBMP("salida.bmp");
}
else
{
cout << "No se pudo escribir el pixeldata." << endl;
}
}
delete pixelData;
delete mypixelData;
The code above draws a white box on the image.
Now, a new question: How can I add text instead of the box?
Users browsing this forum: No registered users and 0 guests