`matlab` extracting blue channel from 3D image into a 2D monochrome matrix - image

I have an RGB image of which i want to extract the blue channel by doing
new_image = image(:,:,3);
this is now a 2 dimensional matrix, however I want to apply a filter on it using the filter2() function and displaying this filtered image using image() or imshow(). when using the imshow() to display the image, the display is grayscale. how can i arrange this so that i will have blue filtered monochrome image?

Either put it back into an RGB matrix with the R and G channels set to zero or create a colormap.

Related

Get pixel values from image: Matlab

I have a simple green fluorescent image. I want to find the total number of pixels that are above a specific value using MATLAB. I don't know where the pixel values are stored in an image.
Here is the green fluorescent image. I want to know which percentage of the pixels have value of more than a specific threshold. For example in this image, if the pixel value in the cells are around X, then I want to find the total number of pixels that are above X.
If you read a colored image using imread, you get a 3D matrix in which the first two indices are the image coordinates; (row, columns); and the last index represents the color channels. For the typical use case of an RGB image, the color channels are:
1 = red
2 = green
3 = blue.
Other possibilities are grayscale, CMYK and indexed images. Please check the official documentation for more information.

How to seprate RGB planes as three different gray scale images?

I want to seprate RGB planes of a color image as three gray scale image in MATLAB. But they are colored. How can I do it? I use the below code:
red = I(:,:,1); % Red channel
green = I(:,:,2); % Green channel
Using image will show the matrix as an image with the default colour map of whatever version of MATLAB you are using. For version R2014b and higher, it will show this in the parula colour map and other versions show this in the jet colour map. If you wish to visualize this as a grayscale image, you must use colormap gray; after you call image.
However, if you have the Image Processing Toolbox, you can simply use imshow and single channel images default to showing the contents as grayscale.

How to convert a RGB image to a two dimensional image in Matlab

I have a RGB image called imrgb, the size of which is 320*512*3.
I want to know how to convert it to a two dimensional image?
I saw some colorful images, but they are still two dimensional instead
of three dimensional. Can anyone tell me how to convert it to a
two-dimensional image but still looks colorful?
If I understood right you can store the image data as a 2D array and use a colormap to assign it colors, displaying it as a "colorful" image. In this case the colormap will be a Nx3 array where each row corresponds to an index present (or not) in the image data. So if the colormap is a 256x3 array, for example, the image will be made of indices ranging from 0 to 255.
For example, let's consider the peppers.png demo image that ships with Matlab. Let's read and use the rgb2ind function to store the image data in variable X and its associated colormap in variable map.
a = imread('peppers.png');
[X,map] = rgb2ind(a,256);
If we ask the size of X, we get:
ans =
384 512
So a 2D variable, even though the original image (a) was 3D (rgb).
If we wish to display this 2D data as a colorful we need to provide a suitable colormap. For instance, we can use the original colormap (stored in map) in order to get the following:
image(X)
colormap(map)
axis off
or we can use any other colormap of our choice.
For example:
image(X)
colormap(jet(200)) %// The size can be different than the original colormap
axis off
yielding:
So as you see the image looks 3D but the data is actually 2D.
Is this what you meant?

View pixel intensities of an image

How to view the pixel intensities of an image in matlab by moving the mouse pointer over the image?
I used:
imshow(imread('image.jpg'));
But there is no option to view the pixel intensities of each pixel in the image.
For example,
In MS-paint, while moving the mouse pointer
over the image we can see the location of
the pixel such as (20, 117) at the status bar.
But I need to see the pixel intensity instead.
Is there any other option to view it. Or I need to code to view it?
One other option which is more interactive is
imtool(imread('image.jpg')); % For GrayScale Image
imtool(rgb2gray(imread('image.jpg'))); % For RGB Image
If you want to create an intensity map, you can use MATLAB's rgb2gray. This will convert the n-by-m-by-3 RGB array you got from imread to an n-by-m matrix which contains the pixel intensities.
You can then point the interactive data cursor to this intensity matrix for the current mouse coordinates.
you have impixelinfo and impixelinfoval for showing interactive information.

How to convert gray scale image which assigned threshhold value in some pixel of original RGB image to RGB?

I have original RGB image.
then, I convert it to gray scale.
then, I assign new threhold value into some pixel.
then, I need to convert the gray scale image from step#3 to RGB image.
I am trying on the step#4. Could you help to advise?
Check out rgb2hsv and hsv2rgb in matlab. Then threshold on the value matrix. This makes more sense to me.
Another possibility is to convert to grey scale but keep the original colour image. Then create a mask by thresholding the grey scale image and use that mask to discard the pixels above/below your threshold on the colour matrix.

Resources