Filter löschen
Filter löschen

how to get the pixel value of histogram?

4 Ansichten (letzte 30 Tage)
mohammed
mohammed am 14 Jan. 2014
Bearbeitet: DGM am 4 Jun. 2024
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.

Antworten (1)

DGM
DGM am 4 Jun. 2024
Bearbeitet: DGM am 4 Jun. 2024
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
ans = 11x1
0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% show how the hues were shifted
comp = [im(1:250,:,:); im2uint8(outpict(251:end,:,:))];
imshow(comp)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by