MATLAB Answers

imadjust returns error only supported for 2d-grayscal images

37 views (last 30 days)
Matpar
Matpar on 16 Jun 2019
Commented: Matpar on 17 Jun 2019
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

Sign in to comment.

Accepted Answer

Walter Roberson
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)

  1 Comment

Matpar
Matpar on 17 Jun 2019
Ahhh! I see, I will try that to see if that was my error. Thanks a mill! Will stay in touch as a newbie I'm sure there will be more questions! Thanx once more

Sign in to comment.

More Answers (1)

Image Analyst
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

Matpar
Matpar on 16 Jun 2019
Hi,
Thanks for the answer and acknowledging me however, I've gathered the understanding of what they mean. What I am lacking is the understanding of my code and why it is not doing what it should as that of the tyre example! The task is the same referencing the example of the tyre in MATLABS enhancing the contrast of images. How is it that the tyre example is functional and my code produces the error? That conundrum is what I'm hoping to resolve! I apologise if the phrasing of my request was indifferent! Thanks in advance
Image Analyst
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);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by