Setting Image Contrast Window Auto

Hello every one,
i am trying to edit the intensity or you could say the Viewing Window of a image, i am aiming to have it be done automatically rather than opening the IMTOOLS then pressing on the contrast and setting the window numbers manually. is that possible ??
thanks every one :)

 Réponse acceptée

Sarah Wait Zaranek
Sarah Wait Zaranek le 8 Mar 2011

0 votes

imshow will let you specify high and low when you view the image. Syntax here:
imshow(I,[low high])
If you would like to convert a matrix to a grayscale image, you can use the following.
I = mat2gray(A, [amin amax])
If you want to determine an appropriate range of that grayscale image, one of the following may be used.
  • contrast will create a new gray colormap, cmap, that has an approximately equal intensity distribution. See code below.
load clown;
cmap = contrast(X);
image(X);
colormap(cmap);
  • stretchlim will find the limits to adjust (stretch) your contrast. Then you can use imadjust to adjust your image. See code below.
I = imread('pout.tif');
J = imadjust(I,stretchlim(I),[]);
imshow(I), figure, imshow(J)
  • histeq will enhance contrast using histogram equalization. See code below.
I = imread('tire.tif');
J = histeq(I);
imshow(I)
figure, imshow(J)

6 commentaires

Amjed
Amjed le 9 Mar 2011
Hello sarah, ummmm well its not like that unfortunately>> you see the second step is sort off what i am want but i need to adjust the window of my data since its a MATRIX IMAGE filled with numbers ....lets say for example the data are between the -3 to 13 ... i want to have my window set between 0 to 15 .. i can do that manual with the contrast tool but i wanna have it as a code to do it automatically for me for a specific matrix
Amjed
Amjed le 9 Mar 2011
I FOUND IT !! :P ... its imshow(I ,[low high]) THAT what i was looking for!! thanks anyways Sarah :)
Brett Shoelson
Brett Shoelson le 9 Mar 2011
Amjed,
You understand that IMSHOW(I,[LOW, HIGH]) just modifies the display of the data, not the data itself, right? BTW, if you want automatic scaling of the display, try IMSHOW(I,[]) (empty square brackets).
Brett
Sarah Wait Zaranek
Sarah Wait Zaranek le 9 Mar 2011
Thanks, Brett -- see my new answer above.
Amjed
Amjed le 9 Mar 2011
SARAH.. your new answer is perfect i used the mat2gray code.. and it worked perfectly thaaaaaaaaaaaaaanks alot :) and yes imshow is a bad move since i couldnt extract it to the workspace also
Sarah Wait Zaranek
Sarah Wait Zaranek le 9 Mar 2011
Great. I love that you can edit and improve the answers from feedback. Thanks for your clarification.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by