How to fix this error if my image is not two dimensional?

handclah = imread('hand2.jpg');
handclahe = adapthisteq(handclah, 'clipLimit', 0.02, 'Distribution', 'rayleigh');
figure, imshow (handclah);
figure, imshow (handclahe);
The error is shown below:
Error using adapthisteq
Expected input number 1, I, to be two-dimensional.
Error in adapthisteq>parseInputs (line 416)
validateattributes(I, {'uint8', 'uint16', 'double', 'int16', 'single'}, ...
Error in adapthisteq (line 155)
noPadRect, distribution, alpha, int16ClassChange] = parseInputs(varargin{:});

 채택된 답변

Image Analyst
Image Analyst 2021년 11월 23일
You're using it on a color image and you can't do that. It needs a gray scale image. To fix:
handclah = imread('hand2.jpg');
[rows, columns, numberOfColorChannels] = size(handclah)
if numberOfColorChannels == 3
% If it's color, convert it to gray scale.
handclah = rgb2gray(handclah);
end
handclahe = adapthisteq(handclah, 'clipLimit', 0.02, 'Distribution', 'rayleigh');
subplot(2, 1, 1);
imshow (handclah);
subplot(2, 1, 2);
imshow (handclahe);

댓글 수: 5

This really works. Thank you.
Btw, sir. Can I ask what this is for?
[rows, columns, numberOfColorChannels] = size(handclah);
if numberOfColorChannels == 3
Image Analyst
Image Analyst 2021년 11월 24일
편집: Image Analyst 2021년 11월 24일
@Atifah Samuri it gets the dimensions of the image. Your error message said
Error using adapthisteq
Expected input number 1, I, to be two-dimensional.
So that indicates that you sent in a three dimensional image (color), not a 2-D image (gray scale) into adapthisteq(). We need a gray scale image for adapthisteq(), but the number of color channels in your image is 3, so it's RGB Color, not gray scale. So in that case the next line converts it to gray scale.
I see. Thank you sir.
That will solve the error you had, so could you click the "Accept this answer" link for my Answer? Thanks in advance.

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

추가 답변 (2개)

Yusuf Suer Erdem
Yusuf Suer Erdem 2021년 11월 23일
Hello, I used these codes below and it worked for me. Could you try it too? I only used .tif format image instead of .jpg image. I upload my image for you too.
clc; clear; close all;
I = imread('tire.tif');
J = adapthisteq(I,'clipLimit',0.02,'Distribution','rayleigh');
imshowpair(I,J,'montage');
title('Original Image (left) and Contrast Enhanced Image (right)')
Dilla
Dilla 2024년 7월 8일

0 개 추천

clc; clear; close all;
I = imread('pout.tif');
figure, imshow(I);
figure, imhist(I);
J = imadjust(I);
figure, imshow(J);
figure, imhist(J);
K = imadjust(I,[0.3 0.6],[0 0.3]);
figure, imshow(K);
figure, imhist(K);
L = imadjust(I,[0.3 0.6],[0.6 1]);
figure, imshow(L);
figure, imhist(L);
I use this code on jpg images, why doesn't it work?

카테고리

도움말 센터File Exchange에서 Display Image에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2021년 11월 23일

답변:

2024년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by