Grouping hex color values - matlab

I am trying to write my own 3d topography-type program in matlab that will take a 2d thermal image and create a 3d model based on the intensity of colors in the 2d image.(white is the highest peak, red is lower, orange is lower...) I have extrapolated the hex and RGB color values of each of the pixels and sorted them into an array that indexes the place of the pixel in the image. There are thousands of unique colors. I need to design an algorithm that will evaluate which color grouping each pixel falls into. (white, red, orange...) without having to physically view each unique color.
I have extracted the hex values from matlab into excel. I alpa-numerically ordered the values and saw that some adjacent values do not lie in the same color family. (ex. #00024C is blue and #000300 is black, yet they are adjacent) Is there some kind of threshold built into matlab that I can use to sort the colors?

Related

How to determine color in MATLAB

I would like to map HSV values to color names in MATLAB. I have converted RGB to HSV and thresholded the values using a series of if statements in order to determine the color . However I would instead like to map the values to defined color names. Is this possible in MATLAB?
If you're working with an mxnx3 (i.e. 2D with 3 channels) RGB image im, then typically the red channel is im(:,:,1), green is im(:,:,2), and blue is im(:,:,3). So if you want the RGB values at some point (x, y), then you can get the vector by im(x,y,:).
If you just want to convert HSV values to RGB, then you can use the function hsv2rgb.

what is map and level in im2bw in matlab?

I want to convert RGB image to binary image for processing in matlab ,
its important to choose variables exactly,
so I need to know exacly what is map and level in im2bw(x,map,level) ?
Map is used only when the image is of map datatype. Essentially map is a format of storing images where each pixel is represented by a number. The numbers are stored in a lookup table called map. The map images are often more compressible than regular images. When the image has to be displayed, the value of pixel is displayed based on the lookup table.
In this case, im2bw just looks at the greyscale value of each pixel and then thresholds.
The level is the greythresh of the image [0-1]. It can be used to change the luminescence of the image.
The map is a colormap. Here is the information from mathworks:
"A colormap is an m-by-3 matrix of real numbers between 0.0 and 1.0. Each row is an RGB vector that defines one color. The kth row of the colormap defines the kth color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of red, green, and blue."
The colormap can be used to change the image's colors.
http://www.mathworks.com/help/images/ref/im2bw.html
http://www.mathworks.com/help/matlab/ref/colormap.html

Plotting images in different colors

I have a gray scale image where I have marked the pixels from 1 - 16.
I want to visualize different intensity pixels in different shades of colors. What is the easiest way to do it such that these numbers 1-16 can be anything ( for eg 5,10,20 ).
I have looked at colormap but am unable to use it in this fashion.

how to detect colour from an image matlab?

we are doing a mat lab based robotics project.which actually sorts objects based on its color so we need an algorithm to detect specific color from the image captured from a camera using mat lab.
it will be a great help if some one can help me with it.its the video of the project
In response to Amro's answer:
The five squares above all have the same Hue value in HSV space. Selecting by Hue is helpful, but you'll want to impose some constraints on Saturation and value as well.
HSV allows you to describe color in a more human-meaningful way, but you still need to look at all three values.
As a starting point, I would use the rgb space and the euclidian norm to detect if a pixel has a given color. Typically, you have 3 values for a pixel: [red green blue]. You also have also 3 values defining a target color: [255 0 0] for red. Compute the euclidian norm between those two vectors, and apply a decision threshold to classify the color of your pixel.
Eventually, you want to get rid of the luminance factor (i.e is it a bright red or a dark red?). You can switch to HSV space and use the same norm on the H value. Or you can use [red/green blue/green] vectors. Before that, apply a low pass filter to the images because divisions (also present in the hsv2rgb transform) tend to increase noise.
You probably want to convert to the HSV colorspace, and detect colors based on the Hue values. MATLAB offers the RGB2HSV function.
Here is an example submission on File Exchange that illustrate color detection based on hue.
For obtaining a single color mask, first of all convert the rgb image gray using rgb2gray. Also extract the desired color plane from the rgb image ,(eg for obtaining red plain give rgb_img(:,:,1)). Subtract the given plane from the gray image........

An explanation for this MATLAB code snippet

Consider:
%# load a grayscale image
img = imread('coins.png');
%# display the image
figure
imshow(img,[]);
%# false-color
colormap('hot')
The above code is from here:
Infrared image processing in Matlab
But I don't understand how figure (what's the difference with/without it?) and colormap (how does it affect the already shown image?) work?
figure is not required, imshow just displays img on it. If a figure hadn't been opened, imshow would've created a new one.
The colormap colors the intensities of the image. The hot map colors values in increasing intensity with black, red, yellow, and white-hot. Another popular colormap is jet which has a number of interesting colors.
False colors
So the matrix you want to see has intensities which can have any range of values. For better visualization, the intensities are displayed in a range of colors or a set of false colors. Normally, a grayscale image will display an image is shades of grey, where white is maximum and black is minimum. False color is an extension of that concept with several colors in between (like jet) and an effect of metal being heated in hot.
Colormap at the pixel level
Suppose you have a matrix with pixel values ranging from [cmin xmax]. Now, normalize the values so that the range is [0,1]. Also, suppose you have a color map, such that a range of colors are mapped to some values from 0 to 1 (e.g. 0.5 is mapped to RGB(100,200,100))- then you get the false color mapping by finding the closest intensity in the map and display the corresponding color.
More on colormap in the MATLAB documentation. I've included some picture from that link here:
Jet
(source: mathworks.com)
Bone
alt text http://www.mathworks.com/access/helpdesk/help/techdoc/ref/bone_spine.gif