Discussion:
24 bit png - display properly in intensity graph
(too old to reply)
DonRoth
2008-07-08 20:40:05 UTC
Permalink
I have tried various methodologies to get the attached 24-bit .png file to display properly in a intensity graph container.  It displays fine in picture control and vision container, but I cannot use those containers in this application.  See the attached strategy I tried. The color table is empty, and the color to RGB strategy does not seem to work properly. Any thoughts?


test.png:
Loading Image...


test_open_png.vi:
http://forums.ni.com/attachments/ni/170/338779/2/test_open_png.vi
Pakman
2008-07-10 08:40:06 UTC
Permalink
Hi Don,

The LabVIEW Help for the Unflatten Pixmap VI states:

"colors is an array of RGB color values that correspond to the
values in the pixmap output. For the 24-bit
pixmap, LabVIEW ignores this output."

Thus, I converted your 24-bit PNG to an 8-bit BMP.&nbsp; Then, I modified the code so that the Z Scale ยป Marker Values[] are set to match the color table exactly.&nbsp; The resulting intensity graph seems to match the original BMP, but I don't know why the Z Scale displays a couple solid colors instead of 256.&nbsp; I'll continue to look into the issue, but I hope this at least gets you started.<img src="Loading Image..."> Message Edited by Pakman on 07-10-2008 03:29 AM


open_bmp1.vi:
http://forums.ni.com/attachments/ni/170/339440/1/open_bmp1.vi


demo1.PNG:
http://forums.ni.com/attachments/ni/170/339440/2/demo1.PNG


bmp image.zip:
http://forums.ni.com/attachments/ni/170/339440/3/bmp image.zip
DonRoth
2008-07-10 14:40:07 UTC
Permalink
Hello Peter: Thanks for looking into this.How did you convert the 24-bit png to 8-bit png?&nbsp; Did you do this somehow within LabVIEW (because I would need to do this programmatically)?I see the help file information, but the color information is available somewhere since the image displays perfectly in the picture control and vision containers.&nbsp; Isn't there any way to extract it?Thanks,Don
Pakman
2008-07-14 07:40:04 UTC
Permalink
Hi Don,

I converted from 24-bit png to 8-bit png with MS Paint.&nbsp; If you need to do it programmatically, however, you can <a href="http://www.imagemagick.org/script/binary-releases.php#windows" target="_blank">download</a> and install <a href="http://www.imagemagick.org/script/index.php" target="_blank">ImageMagick</a> ( Note: Make sure you select a Q8 version
or the conversion process won't work correctly).&nbsp; ImageMagick allows us
to manipulate images via the Windows command line.&nbsp; This ability is
crucial because we can then invoke conversion commands using LabVIEW's
System Exec.vi.&nbsp; Refer to the attached example VI, and keep in mind
that this is only one solution.&nbsp; You may be able to find a DLL and use
the Call Library Function Node, or you could even write your own
conversion process with LabVIEW!

To address your second question: you're right.&nbsp; The color information is available somewhere.&nbsp; Each pixel in a 24-bit image is made up of three main colors: Red, G reen, and Blue (the most significant byte is all 0's and represents the alpha channel in 32-bit images).&nbsp; In LabVIEW, the image array within the image data
cluster stores all bytes pertaining to color.&nbsp; Since it's datatype is
U8 (byte size), however, we cannot store 3 bytes of RGB information.&nbsp;
Thus, these values are split across 3 bytes for every pixel.&nbsp; So, in
your particular image, which has a size of 570 x 248 pixels = 161,880
pixels, the image array has a size of 3 * 161880 = 485,640.

What then happens in the Unflatten Pixmap.vi for 24-bit images is that
the RGB bytes are combined to form one 32-bit dword.&nbsp; For example, if a
certain pixel's color is orange (R: 255, G: 128, B: 65), the resultant
value is 255 &lt;&lt; 16 + 128 &lt;&lt; 8 + 65 = 16,711,680 + 32,768 +
65 = 16,744,513.&nbsp; Therefore, each index of the 24-bit pixmap 2D array
output contains all the information needed to color one pixel.

Finally, the image appears blue on the intensity graph because the
Color to RGB.vi is only returning a value between 0 - 255 on the green
output.&nbsp; Since green is represented in the second byte and blue in the
first, the 00 - FFh value has to map to blue.P.S. What is that (freaky) image of, haha?Message Edited by Pakman on 07-14-2008 02:14 AM


programmatically_convert.vi:
http://forums.ni.com/attachments/ni/170/340421/1/programmatically_convert.vi


test.png:
Loading Image...
tst
2008-07-14 09:10:07 UTC
Permalink
You can also find an LVOOP wrapper for ImageMagick which should make it easier to use <a href="http://forums.lavag.org/-file90.html" target="_blank">here</a>.
If you want to use it, you should read that page carefully. Apparently, getting it to work in an executable can currently be tricky and you also need to get some&nbsp;<a href="http://forums.jkisoft.com/index.php?showtopic=233" target="_blank">OpenG</a> VIs.
DonRoth
2008-07-14 12:40:10 UTC
Permalink
Thanks again for taking the time to look into this.
I understand how the color planes are stored and converted to one value.&nbsp; In my example, I was extracting the bottom (green) plane to pull out 8-bits so you are correct, the overall image then would not show up properly.
I need to find a way to do this programmatically in LabVIEW, without ImageMajick.&nbsp; Since we&nbsp;can get&nbsp;the R, G, B color plane in formation using the 'color to RGB.vi', as you state, it should be possible to convert to 8-bit png (or. bmp)&nbsp;in LabVIEW.&nbsp; Exactly how to do that now is what I need to determine.
&nbsp;
Sincerely,
&nbsp;
Don
Pakman
2008-07-16 05:40:06 UTC
Permalink
Hi Don, First, I assume that you want to keep the colors from the original 24-bit image, right?&nbsp; You would not be content with converting it to an 8-bit gray scale?Second, <a href="http://homepages.inf.ed.ac.uk/rbf/HIPR2/quantize.htm" target="_blank">this</a> website on color quantization provides two algorithms that you can try coding in LabVIEW to achieve the transformation from 24-bit to 8-bit.&nbsp; I have not had the time to come up with something myself, but I'll be sure to post it if/when I do.&nbsp; Keep me updated with how you're progressing!
DonRoth
2008-07-16 12:40:07 UTC
Permalink
The link you provide gives an error and comes up blank.&nbsp; Can you post the actual link address?
Yes, I need the original color scale.&nbsp;(I can convert that to gray scale later if I need to).
I'm tied up for the next 10 days with other work but I also will keep you updated if I am able to do anything.&nbsp;
&nbsp;
Sincerely,
DonMessage Edited by DonRoth on 07-16-2008 07:34 AM
DonRoth
2008-07-16 13:10:07 UTC
Permalink
ps. My bad, the link works fine.&nbsp; Internet Explorer had been upgraded at our site and was not working properly until a reboot.&nbsp; Thanks again for the link. Sincerely,Don
Pakman
2008-08-13 05:40:21 UTC
Permalink
Hi Don,I thought the conversion from 24-bit to 8-bit color images was an interesting problem, so I've finally coded up a solution.&nbsp; It's based upon the popularity algorithm found on the <a href="http://homepages.inf.ed.ac.uk/rbf/HIPR2/quantize.htm" target="_blank">website</a> that I posted earlier.&nbsp; Each color in the image is placed into an array with the 256 most frequently occurring used for the 8-bit color array.&nbsp; Those colors that are not in the array are then "cast" to the color closest in value.&nbsp; I've tested it for a couple images so far, and it performs decently.&nbsp; Here are some of the results: <img src="Loading Image..."><img src="Loading Image..."> <img src="Loading Image..."><img src="Loading Image..."> Will this work for your application?Message Edited by Pakman on 08-13-2008 12:38 AM


test4.png:
http://forums.ni.com/attachments/ni/170/348872/1/test4.png


test1.png:
http://forums.ni.com/attachments/ni/170/348872/2/test1.png


test3.png:
http://forums.ni.com/attachments/ni/170/348872/3/test3.png


test2.png:
http://forums.ni.com/attachments/ni/170/348872/4/test2.png


24_to_8bit.llb:
http://forums.ni.com/attachments/ni/170/348872/5/24_to_8bit.llb
DonRoth
2008-08-13 16:40:06 UTC
Permalink
This looks like a great, if not perfect, workaround.&nbsp; I have not had time to get back to this yet as I have been on travel and tied up with other software issues.&nbsp; Thanks a lot for your effort and if I have the time to work more on this, I will post any new results.&nbsp;This solution should now allow&nbsp;display in intensity graph since a color table is available.&nbsp;&nbsp;Sincerely,&nbsp;DonMessage Edited by DonRoth on 08-13-2008 11:18 AM
Continue reading on narkive:
Search results for '24 bit png - display properly in intensity graph' (Questions and Answers)
17
replies
What are the myths of global warming?
started 2007-05-18 06:56:07 UTC
global warming
Loading...