createScaledImage-c't Interpolation-abnormal termination

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

createScaledImage-c't Interpolation-abnormal termination

#1 Post by alwittta »

Dear friends

Could anyone please help me to fix this problem.

I am having an abnormal termination problem, when using the function createScaledImage of the DicomImage class.

Error is happening from the internal function

Code: Select all

void reducePixel(const T *src[], T *dest[])
(module: DcmImagele, file: discalet.h):

Following is the code for scaling an image, reduce the size to 800

Code: Select all

#define MAX_VALUE 800
int nOrgWidth =  1576;
int nOrgHeight = 1976;

// scale the image to 800
if(nOrgWidth > MAX_VALUE  || nOrgHeight > MAX_VALUE)
{
	if(nOrgWidth > nOrgHeight)
		dScaleFactor = nOrgWidth / (double) MAX_VALUE;
	else
		dScaleFactor = nOrgHeight / (double) MAX_VALUE;
        // dScaleFactor  = 2.4700000000000002
        unsigned long widthTotal = nOrgWidth / dScaleFactor; // 638
	unsigned long heightTotal = nOrgHeight / dScaleFactor; // 799

	DicomImage *pCurImage = orgDi->createScaledImage(widthTotal, heightTotal, 2);
}
But the same code is working if I use the following code :

Code: Select all

int nOrgWidth =  1576;
int nOrgHeight = 1976;

unsigned long widthTotal = nOrgWidth / 2;
unsigned long heightTotal = nOrgHeight / 2;

DicomImage *pCurImage = orgDi->createScaledImage(widthTotal, heightTotal, 2);
From one of the previous thread
viewtopic.php?t=473&highlight=createscaledimage
, I understand that here c't Interpolation algorithm is used for scaling.

Also, there is no similar abnormal termination problem in pbmplus algorithm with createScaledImage (when using the above code).

Please provide a solution

Thanks and Regards
Alvin

Per
Posts: 99
Joined: Mon, 2007-09-03, 10:53
Location: Trondheim, Norway
Contact:

#2 Post by Per »

Try using the pbmplus algorithm instead. I found that the c't algorithm crashes on some series.

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#3 Post by alwittta »

Dear Per,

Thanks for the reply.

When using c't Interpolation algorithm, image clarity is really good as compared with the output of the pbmplus algorithm.
ie. Output of pbmplus algorithm is more blurry or pixelated.
It will be good for the users to see the images in more clear and accuracy.
And in the case of Medical Images, clarity and accuracy has more importance.

What I understand is, the problem is more with the calculation of scaled image’s width and height values. If I pass the exact half of the size of the original image, then it seems the createScaledImage function is working fine with c’t Interpolation algorithm(I tested with around 20 images).

Is that a known bug in DCMTK library or the problem is with c't interpolation algorithm?

Please provide a solution to this issue.

Anybodies help is highly appreciated.

Thanks and Regards
Alvin

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

There is a known bug in the algorithm/implementation which only appears for image with an odd number of columns – if I remember correctly.

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#5 Post by alwittta »

Dear Jörg,

Thank you very much for the quick reply, which points me on the right direction and for a wonderful toolkit.

Regards
Alvin

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#6 Post by Jörg Riesmeier »

I think I've found and fixed the bug in the implementation of the c't algorithm. After some more testing I'll make it available as a snapshot.

I've also added two more algorithms for a "better" magnification of images: a bilinear and a bicubic one kindly provided by a DCMTK user.

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#7 Post by alwittta »

Thank you Jörg.

Please provide us the snapshot link once you complete the testing.

Thanks and Regards
Alvin

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#8 Post by Jörg Riesmeier »

The current snapshot is now available for download. I hope that this also solves your problem ...

Per
Posts: 99
Joined: Mon, 2007-09-03, 10:53
Location: Trondheim, Norway
Contact:

#9 Post by Per »

Could you please point out which of the changes fixed the problems with the c't algorithm? I am afraid that using cvs snapshots is not an option here.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#10 Post by Jörg Riesmeier »

Here's the diff for "dcmimgle/include/dcmtk/dcmimgle/discalet.h" (reducePixel() routine):

Code: Select all

857c925
<                         offset = OFstatic_cast(unsigned long, byi - 1) * OFstatic_cast(unsigned long, Columns);
---
>                         offset = OFstatic_cast(unsigned long, byi) * OFstatic_cast(unsigned long, Columns);
860d927
<                             offset += Columns;
874a942
>                             offset += Columns;
I just discovered that almost the same code is also used in the expandPixel() routine of the c't algorithm. So, I'll also fix that in order to avoid unwanted integer overflows/underflows :?

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests