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

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.

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.

block image detection

i want to detect color from a pixelated image, and then, turn the specific pixel into different color?
for example:
pixel with B/G/R < 150 re-color it to white. and pixel with B/G/R > 150 to black or stay.
is it possible? if yes, how? i need guidance.
The answer is to convert your image into HSV Color Space!
You can Mask out Blue color from the Image using inRange function as follows:
Mat mInput_Bgr,mInput_HSV,mBlueMask,mDestination;
mInput_Bgr= imread(FileName_S,1);
imshow("mInput_Bgr",mInput_Bgr);
cvtColor(mInput_Bgr,mInput_HSV,COLOR_BGR2HSV);
inRange(mInput_HSV,Scalar(104,200,0),Scalar(132,255,255),mBlueMask);// You can play with all the values to choose your desired color
imshow("mBlueMask",mBlueMask);
mInput_Bgr.setTo(Scalar(255,255,255),mBlueMask);// You can set what ever Color Value
imshow("Corrected_mInput_Bgr",mInput_Bgr);

Matlab: How can I find the number of black pixels in a color image?

I wish to find the number of black pixels in a color image using MATLAB, how can I do it?
Thanks.
Use nnz like this -
nnz(all(im==0,3))
where im is your image data.
Alternatives - sum(reshape(all(im==0,3),[],1)) and sum(sum(all(im==0,3))).
The assumption here is that black pixels are triplets (0,0,0).
Instead if you define black pixels as pixels that have values in the interval [0 th] for the same pixel location across all channels, use this -
nnz(all(im<=th,3))

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.

is there any difference between grey scale image and binary image?

is there any difference between grey scale image and binary image?
Yes, the one is grayscale, e.g. gray scales from 0.255, the binary imange is binary, that means black(0) or white(1).
EDIT: Convert grayscale to binary. Directly converting color images (like RGB) to binary is not that easy, because you have to handle every color channel within the image seperatly.
Converting to binary is done using a ceratin threshold. E.g. you can say, all pixels with gray > 125 will become white, the others black.
There are several thresholding algorithm out there, but maybe the most common is Otsu. You can find it here Thresholding by Otsu
Yes, but I'm not sure what this has to do with C++ or programming. A binary image could be an image where pixels are only either red or blue.
Binary Image: http://en.wikipedia.org/wiki/Binary_image
Grayscale Image: http://en.wikipedia.org/wiki/Grayscale
A binary image has only two values for each pixel, 0 and 1 corresponding to black and white (or vice versa). A gray scale image has a certain number (probably 8) bits of information per pixel, hence, 256 possible grey values.
Of course, a grey scale image has a binary representation, but the smallest size of information is not a bit, so we don't call it a binary image.
edit Assuming you want to convert in Matlab, use im2bw. If you're not using Matlab, the idea of binarization is explained on that page as well. It's not difficult to port, it boils down to comparing every pixel to a threshold value.
Black and White image contains only two levels.
Gray image represent by black and white shades or combination of levels for e.g.
8 bit gray image means total 2^8 levels form black to white 0 = black and 255 is White.
Yes,
A binary image is one that consists of pixels that can have one of exactly two colors, usually black and white. It is also called bi-level or two-level.
A gray scale image is a kind of black and white or gray monochrome are composed exclusively of shades of gray.
Yes
Binary Image
A binary image is a black and white image where each pixel value is either 0 or 1. The value 0 represents background or black and the value 1 represents foreground or white.
Grayscale Image
A grayscale image is a black and white image with various shades of gray. The pixel value of a grayscale image is represented as an 8 bit signed integer. i.e values between 0 and 255. The pixel value of the grayscale image represents the brightness of the pixel. The value 0 is black, the value 255 is white, and the values in between makeup different shades of gray.

Resources