Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Sunday, May 6, 2012 11:36:19 PM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Hi,
I am using lead tools 16.5 with C#.NET Framework 2.0.

My application converts dicom images to j2k. This is working fine.
My problem is with dicom images with dicom overlay data.

When I convert dicom image with dicom overlay data to j2k, it converts fine but overlay data on output j2k is missing. I want overlay data to be present on output j2k image. The solution should work for both overlay data in dicom tags and embedded in pixel data.

Following is the code I am using: -
===========================
            DicomDataSet objLTDicomDataSet = new DicomDataSet();
            DicomElement objLTDicomElement = null;
            RasterImage objRasterImageInput = null;
            RasterByteOrder byteOrder;
            objLTDicomDataSet.Load(dicFilePath, DicomDataSetLoadFlags.None);
            objLTDicomElement = objLTDicomDataSet.FindFirstElement(null, DicomTag.PixelData, true);
            DicomImageInformation objDicomImageInformation = objLTDicomDataSet.GetImageInformation(objLTDicomElement, 0);
            if(objDicomImageInformation.IsGray)
                byteOrder = RasterByteOrder.Gray;
            else
                byteOrder = RasterByteOrder.Rgb;
            objRasterImageInput = objLTDicomDataSet.GetImage(objLTDicomElement, 0, 0, byteOrder,
                                        DicomGetImageFlags.AllowRangeExpansion
                                        | DicomGetImageFlags.AutoApplyModalityLut
                                        | DicomGetImageFlags.AutoApplyVoiLut
                                        | DicomGetImageFlags.AutoLoadOverlays);
            objRasterCodecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.TargetSize;
            objRasterCodecs.Options.Jpeg2000.Save.TargetFileSize = targetFileSize * 1024;//KB to Bytes
            objRasterCodecs.Save(objRasterImageInput, j2kFilePath, RasterImageFormat.J2k, 24);

===========================

Please guide me how could I achieve this.
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, May 7, 2012 9:57:22 PM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Hi,
Waiting for your reply.
 
#3 Posted : Tuesday, May 8, 2012 5:37:43 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

The solution will depend on the source bit depth and output format's bit depth.
If your desired output format is 8-bit grayscale, you can extract the image and the overlay plane from DICOM dataset and convert each to 8-bit grayscale before combining them. Save the resultant image as 8-bit grayscale.
Note that you can convert each image to 24-bit before combining them to save as 24-bit J2K.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#4 Posted : Tuesday, May 8, 2012 11:45:10 PM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Hi,
The input bit depth is any (unpredictable) and output bit depth should be 24 as shown in my code snippet earlier.

I have modified my test application to make overlay burn on image using AddCommand before converting it to j2k. This solution is working so far but there are two problems as bellow: -
1) Output image quality is not good.
2) Application crashes on clicking exit button.

You can reproduce second issue by following following steps with my test application attached: -
a) Open application and select dicom image with dicom overlay. One dicom image is already placed in attachment at root path with name OverlayTag.dic.
b) Click the "Convert" button to convert dicom image to j2k.
c) Message box will be displayed saying image converted successfully. Click ok and click on Convert button 5-6 times (repeat the steps b and c 5-6 times).
d) Click on "Exit" button.

You should get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." error.
Stack trace is as bellow: -
   at LDicomDS.{dtor}(LDicomDS* )
   at Leadtools.Dicom.DicomDataSet.!DicomDataSet()
   at Leadtools.Dicom.DicomDataSet.Dispose(Boolean )
   at Leadtools.Dicom.DicomDataSet.Finalize()

My test project is attached for your reference with dicom image I am using and the lead tools dll I am referencing in my application.
Expect your advice on the two issues mentioned above.
 
#5 Posted : Wednesday, May 9, 2012 6:59:12 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Amit,

I want to investigate more about this issue. Please send this issue to support@leadtools.com and include the following information in your email:
 
1. The company you work for
2. The LEADTOOLS serial number(s) you own.
3. The name(s) of the developer(s) using the serial number
4. A link to this forum post.

Maen Badwan
LEADTOOLS Technical Support
 
#6 Posted : Thursday, May 10, 2012 12:59:01 AM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


I will send you a mail with the details you asked for.

By the way, I am also getting different stack trace in some cases.
I am summormzing my issues bellow once again: -
1) How to display dicom overlays on j2k image without quality loss ?
2) Application crashes if steps mentioned in above post are repeated with following stack trace: -
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
   at L_DestroyBitmapList(HBITMAPLIST__* )
   at Leadtools.RasterImage.b()
   at Leadtools.RasterImage.Dispose(Boolean )
   at Leadtools.RasterImage.Finalize()
3) Application crashes if steps mentioned in above post are repeated with following stack trace: -
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
   at LDicomDS.{dtor}(LDicomDS* )
   at Leadtools.Dicom.DicomDataSet.!DicomDataSet()
   at Leadtools.Dicom.DicomDataSet.Dispose(Boolean )
   at Leadtools.Dicom.DicomDataSet.Finalize()

 
#7 Posted : Thursday, May 10, 2012 5:54:43 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

I sent you a reply regarding this issue in Ticket#2012051010000271 that you sent to support. If you need to follow up, please reply to the original ticket.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#8 Posted : Thursday, May 10, 2012 8:49:26 PM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Following is the reply I received through mail.
May be helpful for other users.
=======================

About the application crashing problem, I checked your code and found the cause of the problem. To resolve the problem on your side, try to pass RasterGetSetOverlayImageMode.Copy to the GetOverlayImage() method instead of RasterGetSetOverlayImageMode.NoCopy. The code will be something as follows:

+--------------------+

for(int overlayIndex = 0; overlayIndex < objRasterImageInput.OverlayCount;

overlayIndex++)

{

objRasterImageInput.AddPage(objRasterImageInput.GetOverlayImage(overlayIndex

,

RasterGetSetOverlayImageMode.Copy) );

}

+--------------------+

About the quality of the result image, you are saving to lossy J2k format.

Saving to lossy format will always cause some changes to the image, but if you specify a larger target file size or low quality factor, the resulting image will have very little change from the original.

Thanks,
 
#9 Posted : Monday, May 14, 2012 5:11:00 AM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Hi,
As I mentioned in my post on 10-May-2012, there were three issues.
Out of which issue 2 and 3 are resolved. Application do not crash anymore.

Pending issue is issue 1; i. e. quality loss.
Attached herewith please find sample output images.
CurrentOutput.j2k is current output I get from my test application attached in earlier (09-May-2012) post. Input dicom image is also attached in same (09-May-2012) post.
ExpectedOutput.j2k is expected output.

You can clearly see the quality difference between those two images.
Please advice how should I modify my code to get the expected output.
File Attachment(s):
Output.zip (115kb) downloaded 40 time(s).
 
#10 Posted : Monday, May 14, 2012 10:57:00 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

To get the expected result, you need to use the CombineFastCommand instead of AddCommand. The code will be something as follows:
+--------------------------+
if(objRasterImageInput.OverlayCount > 0)
{
objConvertSignedToUnsignedCommand = new ConvertSignedToUnsignedCommand(ConvertSignedToUnsignedCommandType.ShiftNegativeToZero);

objConvertSignedToUnsignedCommand.Run(objRasterImageInput);

RasterImage destImage = objRasterImageInput.GetOverlayImage(0, RasterGetSetOverlayImageMode.Copy);

ColorResolutionCommand ColorResolution = new ColorResolutionCommand();
ColorResolution.BitsPerPixel = 24;
ColorResolution.Order = RasterByteOrder.Bgr;                
ColorResolution.Run(objRasterImageInput);
ColorResolution.Run(destImage);
                 
CombineFastCommand CombineFast = new CombineFastCommand();
CombineFast.DestinationRectangle = new Rectangle(
0,
0,
destImage.Width,
destImage.Height);
CombineFast.SourcePoint = Point.Empty;
CombineFast.DestinationImage = destImage;
CombineFast.Flags = CombineFastCommandFlags.OperationAdd;
CombineFast.Run(objRasterImageInput);

 
objRasterImageInput = destImage;
}
+--------------------------+

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#11 Posted : Tuesday, May 15, 2012 3:13:38 AM(UTC)

Amit  
Amit

Groups: Registered
Posts: 101


Thanks,
I will check this and will get back to you.

By the way, please remove the attachment from post 09-May-2012.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.158 seconds.