imadjust returns error only supported for 2d-grayscal images
44 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 16 Jun 2019
.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 Comments
DGM
on 26 Oct 2022
Edited: DGM
on 26 Oct 2022
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.
More Answers (1)
Image Analyst
on 16 Jun 2019
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 Comments
Image Analyst
on 16 Jun 2019
Since they want the gray scale version of your image, use gbird rather than birds:
birds_histeq = histeq(gbird);
birds_adapthisteq = adapthisteq(gbird);
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!