Change the image contrast using imtool

1 view (last 30 days)
Marko Baros
Marko Baros on 20 Aug 2012
Hey!
I need a little push about one simple problem, and I want to automate one thing.
For example: Img is a grayscale image and I need to put min and max values as [0 160], then I want to 'Adjust Data', and save an output image.
imtool(Img,[0 160])
% here I need line which is for adjusting changed data
ImgOutput=getimage(imgca);
Thank you in advance!
  2 Comments
Jürgen
Jürgen on 20 Aug 2012
Hi,
maybe I am mistaken, but based on your information I do not understand what you want to do? Do you to do? " I want to 'Adjust Data', and save an output image." what do you mean by adjust?
saving an image can be done: saveas(gcf,'YourFig.jpg')
Ryan
Ryan on 20 Aug 2012
I am not sure what you are looking to do exactly, but perhaps imadjust would help?
adjustedImage = imadjust(inputImage,[low_in; high_in], [low_out; high_out]);

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 20 Aug 2012
Edited: Image Analyst on 20 Aug 2012
You can use intlut()
clc; % Clear command window.
workspace; % Make sure the workspace panel is showing.
% Read in sample image.
grayImage = imread('moon.tif');
subplot(1, 2, 1);
imshow(grayImage);
colorbar;
% Create a look up table to map [min, max] to [0 160]
minGL = min(grayImage(:));
maxGL = max(grayImage(:));
lut = zeros(1, 256, 'uint8');
lut(minGL+1:maxGL+1) = linspace(0, 160, maxGL-minGL+1);
lut(maxGL+2:end) = 160;
% Apply the look up table to create a new image
% which will be in the range 0-160.
image160 = intlut(grayImage, lut);
% Display image.
subplot(1, 2, 2);
imshow(image160);
colorbar;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

Community Treasure Hunt

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

Start Hunting!