find the histogram of the image(cameraman)without using the matlab built-in functions for histogram calculations.compare your result with the with those obtained using the functions imhist().display the input image,the two histograms-(yours and matla

조회 수: 6 (최근 30일)
if true
% code
end

채택된 답변

Marwa Ahmeid
Marwa Ahmeid 2017년 3월 20일
편집: Marwa Ahmeid 2017년 3월 20일
%By Marwa Ahmeid
function [y]=myimhist(img)
[r,c]=size(img);
y=zeros(1,256);
for i=1:r
for j=1:c
z=img(i,j);
y(z+1)=y(z+1)+1;
end
end

추가 답변 (3개)

Image Analyst
Image Analyst 2017년 3월 17일
The code you posted won't do it obviously. You need to use a for loop over all rows and all columns. The gray level will be the index of a "counts" array that you'll build up. Hint:
[rows, columns, numberOfColorChannels] = size(grayImage);
counts = zeros(1, 256);
for col = 1 : columns
for row = 1 : rows
  댓글 수: 7
Saravana Kumar Balakrishnan Janaki
your code throws this error 'Array indices must be positive integers or logical values.'
Image Analyst
Image Analyst 2020년 4월 9일
Looks like I said to add 1 in the comment but didn't in the code. Thanks for catching that. Here is corrected code:
function [counts, grayLevels] = MyHistogram(grayImage)
[rows, columns, numberOfColorChannels] = size(grayImage);
counts = zeros(1, 256);
for col = 1 : columns
for row = 1 : rows
% Get the gray level.
grayLevel = grayImage(row, col);
% Add 1 because graylevel zero goes into index 1 and so on.
counts(grayLevel+ 1) = counts(grayLevel+1) + 1;
end
end
% Plot the histogram.
grayLevels = 0 : 255;
bar(grayLevels, counts, 'BarWidth', 1, 'FaceColor', 'b');
xlabel('Gray Level', 'FontSize', 20);
ylabel('Pixel Count', 'FontSize', 20);
title('Histogram', 'FontSize', 20);
grid on;
end

댓글을 달려면 로그인하십시오.


T G
T G 2018년 12월 11일
Thank u so much Image Analyst for helping..

Ankan Banerjee
Ankan Banerjee 2021년 9월 19일
Can histogram be calculated using find() command?
  댓글 수: 1
Image Analyst
Image Analyst 2021년 9월 19일
Yes, if you used a loop to find all the values that fell in a certain range and then sum them up into the appropriate bin, but why would you want to do it that more complicated way?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by