Histogram dips on normalization
显示 更早的评论
So I'm trying to replicate this histogram figure:

But my end result is this:

Where there are dips on green and blue channel. I'm not sure what to do
clear all;
close all;
clc;
% read and convert image into double
palm = imread('palm down.jpg');
doublePalm = im2double(palm);
%split into RGB
redPalm = doublePalm(:,:,1);
greenPalm = doublePalm(:,:,2);
bluePalm = doublePalm(:,:,3);
%normalize count
redPalm = (redPalm-min(redPalm(:)))/(max(redPalm(:))-min(redPalm(:)));
[yRed, xRed] = imhist(redPalm);
greenPalm = (greenPalm-min(greenPalm(:)))/(max(greenPalm(:))-min(greenPalm(:)));
[yGreen, xGreen] = imhist(greenPalm);
bluePalm = (bluePalm-min(bluePalm(:)))/(max(bluePalm(:))-min(bluePalm(:)));
[yBlue, xBlue] = imhist(bluePalm);
%mean
meanRed = mean2(redPalm);
figure;
subplot(1,2,1); plot(xRed, yRed, 'Red', xGreen, yGreen, 'Green', xBlue, yBlue, 'Blue'); title('RGB Channel'); xlabel('Intensity'); ylabel('Normalised Count');
回答(2 个)
KALYAN ACHARJYA
2018-12-21
0 个投票
The given image is quite large, therefor I have checkd with other images and Its works fine.

Have you plot it individually?
Image Analyst
2018-12-21
编辑:Image Analyst
2018-12-21
0 个投票
Like Kalyan said, he doesn't get it. So I think you're showing a histogram of a uint8 image that has undergone contrast stretching.
When you do intensity normalization, that's what happens - you get "holes" or empty bins in the histogram because there are some gray levels that never got anything assigned to them. Let's take an example. Let's say gray level 200 got assigned to 151.4 gray levels. Then let's say gray level 201 got assigned to 152.6 gray levels. That's not much more than a gray level apart. Now, when you go to uint8, the 151.4 will go to 151, and the 152.6 will go to 153. So what went to 152? Answer: nothing! Ta-Da! Zero height bins in your histogram just like you got!
You might try using mat2gray() and see if that fixes it.
If that doesn't fix it, then you can add a plus or minus half a gray level of noise to your image before you normalize. That should fix it.
类别
在 帮助中心 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
