imadjust returns error only supported for 2d-grayscal images
20 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I am new to Matlab,
I have tried this over and over again, I am not sure what it means and it seems challenging.
Can someone pelase guide me through the imadjust command I am new to Matlab?
birds = imread('bird.jpg');
gbird = rgb2gray(birds);
bwbird = imbinarize(gbird);
%birds_imadjust = imadjust(birds);
birds_histeq = histeq(birds);
birds_adapthisteq = adapthisteq(birds);
imshow(birds);
imshow(gbird);
imshow(bwbird);
This is my code. I am not sure if I downloaded the wrong image to use with it, but this is for a professional to decompose.
I appreciate you for taking the time to respond in advance! Thank you!
0 件のコメント
採用された回答
Walter Roberson
2019 年 6 月 16 日
.jpg images are almost always color images. Your code acknowledges that when it does the
gbird = rgb2gray(birds);
In your comment
%birds_imadjust = imadjust(birds);
you attempt to apply imadjust to the color image, not to the grayscale version of the image. imadjust is not designed to work on color images and gives you an error message when you try.
To be consistent with your other calls you would use imadjust(gbird)
2 件のコメント
DGM
2022 年 10 月 26 日
編集済み: DGM
2022 年 10 月 26 日
Imadjust() will work on color images, but for sake of inconsistency, it throws an error if you use the implicit inrange syntax when doing so.
When called with only one argument
B = imadjust(A);
Imadjust() internally calls stretchlim() to find a nominal set of input levels. It's equivalent to:
B = imadjust(A,stretchlim(A));
... but if A is not a 2D array, it just dumps an error instead.
You can always just call stretchlim() explicitly to avoid the error.
A = imread('peppers.png');
B = imadjust(A,stretchlim(A));
imshow([A B])
Though bear in mind that since the input levels are calculated independently per channel, you're likely to cause some shift in color balance. Is that the reason why imadjust() excludes this functionality? Consider that stretchlim() maintains said functionality and exists for the purpose of serving imadjust(). Make of that what you will.
You're always free to come up with input/output levels some other way. There are also other ways to do levels/contrast adjustment on color images.
その他の回答 (1 件)
Image Analyst
2019 年 6 月 16 日
imadjust() finds the tails of the histogram - the 1% points at each end of the histogram. Then it linearly maps those points to the min and max (typically 0 and 255). This has the effect of increasing the contrast of the image.
histeq() does a non-linear stretch according to the shape of the histogram. It is rarely, if ever, useful because it produces unnatural looking images that are not helpful at all. You can ignore it.
adapthisteq() does a linear histogram stretch within a moving window. This is useful for doing a background correction in cases where your objects of interest (foreground) are sitting on top of a background that changes over a large scale.
imbinarize() does a thresholding operation to binarize your image into foreground and background. It may or may not do a good job depending on your image. There are a variety of algorithms you can use to determine the threshold and the default Otsu method may or may not be a good one for your particular images.
2 件のコメント
Image Analyst
2019 年 6 月 16 日
Since they want the gray scale version of your image, use gbird rather than birds:
birds_histeq = histeq(gbird);
birds_adapthisteq = adapthisteq(gbird);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!