0
votes

I have an RGB image m in MATLAB

IMG

I normalized it using the formula

im = mean(m,3);
im = (im-min(im(:))) / (max(im(:))-min(im(:)));

I read that the normalized module stretches the image pixel values to cover the entire pixel value range (0-1) but I still have some steps between 0 and 1 in the histogram of my normalized image.

enter image description here

Can anyone help me out here by explaining the reason of these grey values.

Thank You

1
To clarify: You would like to have a binary image (only 0 and 1)?hbaderts
When I convert my Image to binary I have just 0 and 1 values in my histogram. I want to know why do I have 4 steps in my Normalized RGB Histogram if it stretches the values to zero or 1.Agror
Probably because you haven't binarised it properly. Post some sample data and how you binarised it and I'm sure someone can help.kkuilla
Where is your RGB separation / slicing? Normalising per colour-plane gives 3-histograms or a complex one, using some RGB-based scalar ( for example a Lightness-scalar, or a Saturation-scalar ) according to which to process the normalisation calculus.user3666197
I will add the image and the normalizing step in the question.Agror

1 Answers

2
votes

I assume you use the mean of the three components instead of the function rgb2gray because it has some advantages in your case. (rgb2gray does something similar: it uses a weighted sum).

Subtracting the minimum and dividing by the maximum doesn't convert your image to binary. It will only scale all values to the range (0,1), which is the case in your example. This only means that all values are between 0 and 1, not exactly 0 or 1. If you want a binary image, i.e. only 0 and 1, you will need to use a threshold to convert the grayscale image to binary.

A method which is often used, is to calculate a threshold using Otsu's method:

threshold = graythresh(im);            % calculate threshold
binaryImage = im2bw(im,threshold);     % convert image to binary

If your image is saved as uint8 then normalizing the image should convert your image to binary, as uint8 only can handle integer numbers and any numbers between are rounded. That means you assume the optimal threshold to be at 0.5.