01-08-2016 06:28 AM - edited 01-08-2016 06:29 AM
Hi guys,
I would like to create a color table from this bmp file.
Can anybody please help me?
Solved! Go to Solution.
01-08-2016 06:58 AM - edited 01-08-2016 06:59 AM
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?
01-08-2016 10:34 AM
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.
01-08-2016 12:15 PM - edited 01-08-2016 12:20 PM
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.
01-08-2016 12:26 PM
This example can generate them if you know what colors you want for the various points: https://decibel.ni.com/content/docs/DOC-9294
01-08-2016 12:40 PM - edited 01-08-2016 01:07 PM
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. 😄
01-08-2016 04:34 PM - edited 01-08-2016 04:34 PM
@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)
01-09-2016 01:06 AM
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.
01-10-2016 12:09 PM
01-10-2016 03:05 PM - edited 01-10-2016 03:38 PM
@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)