Vertical flip of DICOM images

All other questions regarding DICOMscope

Moderator: Moderator Team

Post Reply
Message
Author
indrajit_ghosh
Posts: 2
Joined: Fri, 2005-06-10, 18:25
Location: Bangalore, India

Vertical flip of DICOM images

#1 Post by indrajit_ghosh »

Hi All,

The DICOMScope provides the functionality of horizontal flip for DICOM images along with rotation. I am trying to add the functionality of vertical to the application. I am doing this by first rotating the image by 180 degrees and then flipping the image horizontally.

Technically, this approach should work and the end result would be a vertically flipped image. As a matter of fact, it is working fine for all single frame images and the first frame of multiframe images. However, the moment I try to vertically flip a frame apart from the first frame, the vertical file is not happening and instead the end result seems to be same as horizontal flip (doing a getFlip() and getRotate() are returning the proper values but the pixel data of the image seems to be wrongly manipulated).

I even tried to pass a 180 degree rotate and flip together as parameters to DVPSDisplayedArea::rotateAndFlip () (instead of rotate and then flip) and even then the end result looks like a horizontal flip. Strangely only rotate or only horizontal flips are working fine on all the frames of multiframe DICOM images.

It would be great if anyone could help me understand why this might be happening. It could be possible that I am doing something wrong which is not apperant in single frame images but appears in mutiframe images.

Thanks a lot in advance.

Regards,
Indrajit

indrajit_ghosh
Posts: 2
Joined: Fri, 2005-06-10, 18:25
Location: Bangalore, India

RE: Vertical flip of DICOM images

#2 Post by indrajit_ghosh »

Hi All,

Thanks for taking the time to view my questiion. I have found the root cause of the problem. Maybe it can be of help to you too.

There is a bug in the way rotate 180 degrees is implemented in dcmtk (ok, this is a dcmtk problem and maybe it should be in that forum!). The dcmimgle/ dirotat.h contains the DiRotateTemplate class (dcmtk/dcmimgle/include/dirotat.h) which does the pixel by pixel rotation transforms. The function rotateTopDown (T *data []) is responsible for the 180 degrees rotation.

When the function tries to rotate a multiframe image, there is a for loop for all the frames; but the ponter is not incremented to the next frame in it. Hence, it ends up doing a rotate for first frame n number of times if there are n frames.

I guess that the correct implementation for the function would be:

Code: Select all

    inline void rotateTopDown(T *data[])
    {
        register unsigned long i;
        register T *p;
        register T *q;
        register T t;
        register T *s;
        const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
        for (int j = 0; j < this->Planes; ++j)
        {
            s = data[j];
            for (unsigned long f = this->Frames; f != 0; --f)
            {
                p = s;
                q = s + count;
                for (i = count / 2; i != 0; --i)
                {
                    t = *p;
                    *p++ = *--q;
                    *q = t;
                }
                s += count;  // this line was missing in dcmtk and causing all the problems
            }
        }
    }
Regards,
Indrajit

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

#3 Post by Jörg Riesmeier »

Thank you for the bug report and suggested fix. The problem will be fixed in the next release.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests