- If your image is of type "uint8", it should have pixel values in the range [0, 255]. Ensure that your histogram accounts for all possible values, even if they don't appear in the image.
- "imhist" uses fixed bin widths for each possible intensity value. If current implementation is not using the same bin width, the results will differ.
- Ensure that the image is correctly converted to grayscale and that no preprocessing steps are missing.
- Check for edge cases where certain intensity values might not be present in the image, ensuring that the histogram still accounts for all possible values.
result of implementing histogram not exactly like imhist function why?
조회 수: 1 (최근 30일)
이전 댓글 표시
im = imread('CameraMan.jpg');
A = rgb2gray(im);
S = size(A);
[D1, ia, ic] = unique(A);
[R1,C1]=size(D1);
E1=[];
for i = 1 : R1
F1 = sum(A(:)==D1(i));
E1(i)=F1;
end
[counts,blocklocation]=imhist(A);
counts= counts';
figure;
subplot(1,2,1);
bar(E1);title('bar');
subplot(1,2,2);
imhist(A);title('hist');
댓글 수: 0
답변 (1개)
Vidhi Agarwal
2024년 11월 26일
편집: Vidhi Agarwal
2024년 11월 26일
I understand you are facing discrepancy between implementation of a histogram and MATLAB's "imhist" function. This might be due to several factors. Below are some potential reasons:
Revised version of code is given below:
im = imread('CameraMan.jpeg');
A = rgb2gray(im);
% Initialize the histogram array for 256 bins
E1 = zeros(1, 256);
% Calculate histogram manually
for i = 0:255
E1(i+1) = sum(A(:) == i);
end
% Compute using imhist
[counts, ~] = imhist(A);
counts = counts';
% Plot both histograms
figure;
subplot(1, 2, 1);
bar(0:255, E1); % Ensure the x-axis matches the intensity range
title('Manual Histogram');
subplot(1, 2, 2);
imhist(A);
title('imhist Function');
For better understanding of "imhist" refer to the following documentation:
Hope that helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!