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 : Tuesday, October 9, 2007 10:10:21 PM(UTC)
boris_qbf

Groups: Registered
Posts: 7


Hi there
I have DIB that i receive from grayscale scanner. DIB is described as 16-bit color in the header, however each pixel value represents intensity of gray rather than RGB.
When i use Leadtools RasterImage object using RasterImage.FromDib() the resulting image has RGB byte order and the image is completely incorrect. Each pixel is interpreted as having 2 bits for R, 5 bits for G and 5 bits for B. What i want it to be - each pixel should be interpreted as 12 bit shade of gray.

How should I process the image or how should I construct it in a first place to get correct grayscale representation?

I'm using Leadtools medical v15 .NET

Thankyou
bk
 

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 : Wednesday, October 10, 2007 9:30:08 AM(UTC)

jigar  
Guest

Groups: Guests
Posts: 3,022

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

Hello,

The FromDib() method only takes standard DIBs.  They have to be in RGB byteorder.  That's why its taking the 12-bit pixel value and making it 2R+5G+5B = 12. What color space is the 12-bit pixel?  Is there a palette in the bitmap?

The object you are using to acquire the DIB from the scanner, does it allow you to save it to a file?  If so, I can help you identify it if it has a palette and maybe the color space/byte order.  After we find out what palette/color space the bitmap is, we can convert it to a standard DIB.

You can zip the BMP and send it to me.  If you have more questions or need some clarity on what I stated, do let me know.

Thanks
 
#3 Posted : Wednesday, October 10, 2007 3:19:51 PM(UTC)
boris_qbf

Groups: Registered
Posts: 7


Thanks jigar

Looks like the image does have a palette. I'm sending you a file sample.

thanks for help
bk

 
#4 Posted : Tuesday, October 30, 2007 5:28:27 AM(UTC)

jigar  
Guest

Groups: Guests
Posts: 3,022

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

UPDATE:

Me and Boris discussed the issue privately through email, and with the help of one of our engineers and Travis, we were able to get a viable solution.

So for any developers out there with a similar issue, can try out the code below.  The issue was, the scanner was returning a 12-bit DIB with a 16-bit header information.  When calling the RasterImage.FromDib() method, it would create the RasterImage but it would be in BGR byte order instead of Gray byte order.  Boris tried to convert the 12bit pixel values to our Leadtools Gray byte order format by applying bit packing.  Bit packing requires two 12-bit values, so that means 2 pixels.  1st pixel = 0xABC, 2nd pixel = 0xDEF.  The bit-packed value will be 3 bytes, BC, FA, and DE.

Second solution he tried was shifting the data 4 bits to the left to get a 16-bit value.  Which worked out, but because of strict medical requirements (cannot alter the original pixel data), he wasn't able to use it.  So we looked for a solution from the engineers, and the code below is what we got from Travis and the engineers.

Boris, if you have any corrections or additions, feel free to reply.  Thanks.

/// Start of code

         RasterSupport.Unlock(RasterSupportType.Medical, "your unlock key");
         RasterCodecs.Startup();
         RasterCodecs io = new RasterCodecs();
         RasterImage img;

         // Load image from disk
         img = io.Load(Application.StartupPath + "\\..\\..\\Test.bmp");
           
         // Create a new image at 16 bpp Gray (We copy the 12 bits into the 16 bits)
         RIV1.Image = new RasterImage(RasterMemoryFlags.Conventional, img.Width, img.Height, img.BitsPerPixel, RasterByteOrder.Gray, img.ViewPerspective, null, IntPtr.Zero, 0);
           
         // Copy Data
         CopyDataCommand copy = new CopyDataCommand();
         copy.DestinationImage = RIV1.Image;
         copy.Run(img);           
           
         // Get Min and Max Bits
         MinMaxBitsCommand mmBits = new MinMaxBitsCommand();
         mmBits.Run(RIV1.Image);

         // Get Min and Max Values
         MinMaxValuesCommand mmVals = new MinMaxValuesCommand();
         mmVals.Run(RIV1.Image);

         // Set Images' Min and Max bits
         RIV1.Image.LowBit = mmBits.MinimumBit;
         RIV1.Image.HighBit = mmBits.MaximumBit;

         // Window Level image for viewing.
         ApplyLinearVoiLookupTableCommand wl = new ApplyLinearVoiLookupTableCommand();
         wl.Flags = VoiLookupTableCommandFlags.None;
         wl.Width = mmVals.MaximumValue - mmVals.MinimumValue;
         wl.Center = wl.Width / 2;
         wl.Run(RIV1.Image);

         RasterCodecs.Shutdown();

/// End of code
 
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.095 seconds.