필터 지우기
필터 지우기

I want to compute histogram for a tif image. But the regular histogram code does not accept my input. so please give me a solution

조회 수: 2 (최근 30일)
[Edit - format code. AU]
originalImage = imread('3-mar-08.tif');
subplot(3, 3, 1);
imshow(originalImage);
>> set(gcf, 'Position', get(0, 'ScreenSize'));
>> drawnow;
>> [pixelCount grayLevels] = imhist(originalImage);
subplot(3, 3, 2);
bar(pixelCount); title('Histogram of original image');
xlim([0 grayLevels(end)]);
??? Error using ==> iptcheckinput
Function IMHIST expected its first input, I or X, to be
two-dimensional.
Error in ==> imhist>parse_inputs at 275
iptcheckinput(a,
{'double','uint8','logical','uint16','int16','single'}, ...
Error in ==> imhist at 57
[a, n, isScaled, top, map] = parse_inputs(varargin{:});

채택된 답변

Image Analyst
Image Analyst 2014년 2월 27일
Try this:
originalImage = imread('3-mar-08.tif');
[rows, columns, numberOfColorBands] = size(originalImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = originalImage(:, :, 2); % Take green channel.
% Alternatively you can call rgb2gray(). Do one or the other, not both.
%grayImage = rgb2gray(originalImage);
else
% It's already gray scale.
grayImage = originalImage;
end
% Now use grayImage everywhere after this that you were using originalImage.
Or you can try my RGB histogram demo, attached below.
  댓글 수: 4
Jos (10584)
Jos (10584) 2014년 2월 27일
I meant: What if all image information is in the other channels and the second channel has no variation in it? For instance, because the image is filtered or so.
X = imread('board.tif') ; X(:,:,2) = 50 ; % create a test image
subplot(2,2,1) ; image(X) % it is still an image!
subplot(2,2,2) ; imhist(X(:,:,2)) % but no variation in the 2nd channel
Image Analyst
Image Analyst 2014년 2월 27일
Well, yeah. You have to know your image and take the approach that makes sense. Taking one color channel is faster than calling rgb2gray() but it doesn't make sense if there's no information there - you'd be better off calling rgb2gray() even though it's slower because it has to do a weighted average of all the extracted color channels.

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2014년 2월 27일
Apparently your array originalImage is not 2D. You can probably see that
ndims(originalImage)
will return 3, suggesting that the image is in RGB format. You might be able to use RGB2IND to convert it.
[X, MAP] = rgb2ind(originalImage)
imhist(X, MAP)
  댓글 수: 2
sandhya chezhian
sandhya chezhian 2014년 2월 27일
[X, MAP] = rgb2ind(originalImage) imhist(X, MAP) ??? Error using ==> rgb2ind>parse_inputs at 131 RGB2IND(RGB) is a deprecated syntax. Specify number of colors, tolerance, or colormap.
Error in ==> rgb2ind at 50 [RGB,m,dith] = parse_inputs(varargin{:});
"im getting this error"..what shud i do??

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by