how to get the pixel value of histogram?
2 次查看(过去 30 天)
显示 更早的评论
Hello
i wants to delete or make some pixel zero , according to the bins.
im = imread ('image');
hsv_im = rgb2hsv(im);
h = hsv_im(:,:,1)
[pixelCount, grayLevels] = hist(h(:), 360);
pixelCount(20:30)=0;
Now i want to get my 'Hue' Matrix with same pixel position and zeros between the bin values from 20 to 30.
0 个评论
回答(1 个)
DGM
2024-6-4
编辑:DGM
2024-6-4
You have the bin values. You know which bins you want. Why are you zeroing the histogram counts instead of changing the image?
% the image
im = imread('rainbow.png');
hsv_im = rgb2hsv(im);
h = hsv_im(:,:,1);
% generate the mask
nbins = 360;
[~, bincenters] = hist(h(:),nbins);
maskrange = bincenters([20 30]) + [-0.5 0.5]/nbins;
mask = (h >= maskrange(1)) & (h <= maskrange(2));
% make the masked region red
h(mask) = 0;
% reassemble the image
hsv_im(:,:,1) = h;
outpict = hsv2rgb(hsv_im);
% it's red
imshow(outpict)
Of course I have to question whether the goal was to actually set orange pixels to red, or whether it was to reshape the entire histogram such that there are no orange pixels. I guess we'll never know.
EDIT:
Just because I felt like it:
% the image
im = imread('rainbow.png');
hsv_im = rgb2hsv(im);
h = hsv_im(:,:,1);
% crudely reshape the histogram
nbins = 360;
[bincounts, bincenters] = imhist(h,nbins);
bincounts(20:30) = 0;
% make the masked region red
hnew = histeq(h,bincounts);
% reassemble the image
hsv_im(:,:,1) = hnew;
outpict = hsv2rgb(hsv_im);
% it's still red
imshow(outpict)
% show that the histogram has a hole in it
subplot(2,1,1)
imhist(h)
subplot(2,1,2)
imhist(hnew)
% inspect that part
countsnew = imhist(hnew,nbins); % need to call imhist() twice
countsnew(20:30) % yes they're zero
% show how the hues were shifted
comp = [im(1:250,:,:); im2uint8(outpict(251:end,:,:))];
imshow(comp)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!