LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create color table from a jpeg

Solved!
Go to solution

Hi guys,

 

I would like to create a color table from this bmp file.

Can anybody please help me?

0 Kudos
Message 1 of 13
(6,420 Views)

Hi Xiang,

 

I would like to create a color table from this bmp file.

You attached a JPG instead of BMP, but that doesn't matter to solve your problem…

 

Read the image using the picture file functions.

Read the pixel values to determine the color value.

Build an array from your color values.

Ready!

 

Where are you stuck? What have you done so far?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(6,398 Views)

Your post content doesn't match your title.

You want to create color table from jpg or bmp?

 

Color table defined only in 8 bit images.

While jpg usually is 24 bit.  So no color table in it.

 

George Zou
0 Kudos
Message 3 of 13
(6,367 Views)

If the file contains a paletted image,  the color map will be part of the image data cluster. Just unbundle it.

 

If it does not contain a paletted image,  it most likely contains more colors that would fit into a color table, so you simply need to round to the closest 256 colors. There are many advanced algorithms available to do that.

 

If the image contains a limited set of colors, just create an array of all the unique entries and arrange them according to the left to right arrangement in the picture.

0 Kudos
Message 4 of 13
(6,349 Views)

This example can generate them if you know what colors you want for the various points: https://decibel.ni.com/content/docs/DOC-9294

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
Message 5 of 13
(6,331 Views)

In particular, yuor image contains exactly 256 pixels horizontally while the rows are redundant, so all you need is read out the 256 colors from left to right and store them in an array containing 256 RGB colors. Should be trivial to do! Unflatten the image and index out a row. 😄

 

0 Kudos
Message 6 of 13
(6,315 Views)
Solution
Accepted by Xiang00

@altenbach wrote:

In particular, yuor image contains exactly 256 pixels horizontally while the rows are redundant, so all you need is read out the 256 colors from left to right and store them in an array containing 256 RGB colors. Should be trivial to do! Unflatten the image and index out a row. 😄


Here's what I had in mind. Works just fine.

(note that the indicator is an array of frameless color boxes from the classic palette.

 

 

 

(Of course if you don't know the image format, you should detect the type and act accordingly. This is just a draft)

 

 

Message 7 of 13
(6,287 Views)

Thank you all guys for the prompt replies.

 

With your advices, now I can get various color tables from this site.

http://rsb.info.nih.gov/ij/download/luts/

I used ImageJ to convert these color tables (lut files) as JPEG and used the suggested vi to extract the rgb information of the jpeg as 1D array.

0 Kudos
Message 8 of 13
(6,255 Views)

Hi Xiang,

 

try this to load *.lut files:

check.png

(Maby you need to sort the order of R, G, B bytes…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(6,190 Views)

@GerdW wrote:

 

try this to load *.lut files:

(Maby you need to sort the order of R, G, B bytes…)


I was looking at these files earlier and it did not look that easy.

I am pretty sure your solution is incorrect. Did you find any documentation on the LUT structure?

Have you tried loading some of the LUTs from that website and compared them to the images?

 

I can read the red-blue LUT as follows, but others seem to have a more complicated structure. Maybe there are headers or simiar?

 

(the graph shows the raw U8 data)

 

 

0 Kudos
Message 10 of 13
(6,172 Views)