how to read th r,g,b values of an quantized image - matlab

Merged with how to read and store rgb values of each pixel after image quantization.
i have quantized an image to 64 colors using [IND,map]=rgb2ind(RGB,64)
my question is,how can i read the red pixel intensity,green pixel intensity and blue pixel intesity of each pixel from the quantized image.
thanking you
dev

Related

Single channel png displayed with colors

I'm checking out the ground truth segmentation masks of the pascal voc 2012 dataset. These are single channel 8-bit uint png files. However when I open these images in either the file browser (nautilus) or the image viewer (eog) they are displayed in colors.
Shouldn't it be displayed in grayscale?
When I store an image as single channel 8-bit uint png file using Matlab, it is displayed in grayscale as expected. What is the difference are there different types of png files?
How can I store it such that my image viewer displays them in colors?
This is the original single channel png:
This is the result after imread and imwrite. Note that NO channel has been added / removed:
Your image files contain indexed images, with an M-by-N index matrix and a P-by-3 colormap matrix. How can you tell? You need to get the second output from imread when loading your images:
[img, cmap] = imread('zuIra.png');
if isempty(cmap)
% Process data as a grayscale or RGB image
else
% Process data as an indexed image
end
If cmap is empty, your data is either an M-by-N grayscale intensity image or an M-by-N-by-3 Truecolor RGB image. Otherwise, you're dealing with an indexed color image, and will have to use both pieces of data in any processing of your image, such as viewing it with imshow:
imshow(img, cmap);
Or when resaving the data with imwrite:
imwrite(img, cmap, 'outfile.png');
If you would rather deal with a single image data matrix (which can make processing easier in some cases), you can convert the indexed image data and associated colormap into an RGB image with ind2rgb:
imgRGB = ind2rgb(img, cmap);
You are dealing with an 1 to 8 bits (variable) per pixel PNG with indexed colors.
When a format uses this technique, color information is not directly stored into the the image pixel data, but in a separate piece of data called palette. A palette can be defined as a predefined array of colors in which each element defines the trichromatic representation (RGB) of a specific color (8 bits per channel, for a total of 24 bits).
The image pixel data does not contain the full specification of a color in the RGB form, but only the indices to the palette colors. Of course, the palette must contain one entry for each pixel color present in the image.
This approach can be seen as a form of compression, in which only a limited set of colors is available in order to save up memory/storage and speed up the display of the image.
Long story short, the result of your imread call is not returning you the color information of the image. Your array contains the indices to the PNG palette elements.
Example
Let's say that you have n indexed PNG that has a width of 3 pixels and a height of 1 pixel. The first pixel is pure red, the second pixel is pure green and the third pixel is pure blue.
In the PNG binary data, the PLTE chunk will contain the following color definitions:
[255 0 0] % Pure Red
[0 255 0] % Pure Green
[0 0 255] % Pure Blue
and the IHDR chunk will define a single channel with the following data:
0 1 2
% 0 = index to the first palette color, pure red
% 1 = index to the second palette color, pure green
% 2 = index to the third palette color, pure blue

How to know the depth value of 24bit depth images in matlab

I am trying to deal with 24bit depth images from NYU Hand dataset in MATLAB.
When i tried to read images as below in MATLAB
img = imread('synthdepth_1_0006969.png');
the form of the variable( img) is 480x640x3 uint8.
My question is, in this case, how do i know the depth value from that?
When I read 8bit or 16bit images in MATLAB, each pixel show the depth value. But
in 24bit case, I don't know how to deal with it...
Thank you for reading my question.
Notice that the image data is 3 dimensional, with the third dimension having a size of 3. That third dimension encodes the red, green, and blue color planes in a Truecolor image. Three uint8 (i.e. unsigned 8-bit integer) color values equates to 24 bits of total color information per pixel.

Increase Yellow Saturation only in RGB or HSV Image (Matlab)

I have an image. I want to selectively increase the saturation of yellow in the image to max. How is this done in the RGB or HSV image space? Thanks.
This needs to be done in HSV (Hue Saturation Value) color space.
If you have the image in HSV, it is very easy (else convert it to HSV). The H is the only variable that gives color information, and if you check the wikipedia page of Shades of Yellow, you'll notice they are all are between 45 to 60 deg. So take you HSV image, select the H in that range and increase the S (saturation) of those values.
In Matlab:
%Read image
imghsv=imread('http://7-themes.com/data_images/out/34/6884934-yellow-flowers.jpg');
imghsv=rgb2hsv(im2double(imghsv));
%pick yellow
yellowIndex=repmat((imghsv(:,:,1)>45/360)&(imghsv(:,:,1)<60/360),[1 1 3]);
yellow=imghsv.*yellowIndex;
%Saturate it
moreSaturation=2;
yellowsaturated=yellow(:,:,2)*moreSaturation;
yellow(:,:,2)=yellowsaturated;
%put it back
newHsv=imghsv;
newHsv(yellowIndex)=yellow(yellowIndex);
result:
Original
Yellow pixels
Saturated

Obtaining the pixel values of gray scale image from a binary image

I do binary thresholding on a 16 bit gray scale image.This would help me in segmenting the region of interest.After binary thresholding,i would like to get the individual pixel intensities which are the intensities of the original 16 bit image and not the binary intensity values say 0,65535...
How can i do this?
Find the region of interest in image segmentation using the binary image. After this, use the pixel locations in the 16 bit image for further processing of the image.
To get a image from your original image, I and a binary (logical) segmented image BW:
I2 = I.*BW;
I2 should have the original values in the ROI and 0 elsewhere. Or, to get just a list of pixels and their values, via logical indexing:
I2 = I(BW);
Alternatively, depending on what you're doing, you may want to use regionprops:
stats = regionprops(BW,I,'MeanIntensity','PixelValues');
For a BW image showing the regions of interest, and a greyscale image I this will return the mean intensity and all list of all pixel values in I for each separate region (defined as a connected areas in BW).

How to change colormap of indexed image to HSV colormap in MATLAB

I am using an indexed image.How do I programatically obtain the pixel intensity values obtained by changing the colormap to hsv in the imtool? Is there a way to change the colormap of the indexed image to hsv(256)?
I am new to MATLAB, kindly help!
I have attached the image below:
Which channel does the imtool display and what does the value '91' in the imtool stand for? How do I obtain this value?
The Pixel info at the bottom displays the following information:
Pixel info: (X, Y): Pixel Value
Here, we have pixel value of 91 at (309, 510). 91 is the pixel intensity in a range of values (mostly 0 to 255). Only 1 channel is being read because it is a grayscale image.
You can create a hsv image out of an RGB image but it doesnt make sense to talk of a hsv conversion for a gray scale image. What you have is a grayscale image.