Reputation: 147
I have designed one MATLAB GUI in which there are two axes for displaying images. I am using 'imcontrast' function to adjust brightness/contrast of the images on first axes. Now, I want to store this enhanced output(brightness/contrast adjusted output) in some variable. As 'imcontrast' function does not returns the output image, so how can i get output image? or Is there any way to read image data from particular axes? I have tried with 'getimage' function but it returns the first image data contained in the Handle Graphics object (i.e previously displayed input image) and not latest brightness/contrast adjusted Image. Please help me out in saving the brightness/contrast adjusted Image given by 'imcontrast' function.
Upvotes: 1
Views: 2284
Reputation: 221514
Use this -
imcontrast(gca) %// Perform imcontrast
waitfor(gcf); %// Wait for figure data to be updated with imcontrast
image_data = getimage(gcf);%// Store image data as image_data variable
How to use within a GUI
Just to showcase on how to use it, you can create a pushbutton with MATLAB-Guide and in it's callback function use this -
%// Show the image on an existing image axes of the GUI.
imshow('pout.tif') %// This image is available in MATLAB image library.
imc_figure = imcontrast(gca) %// Perform imcontrast
waitfor(imc_figure); %// Wait for the data to be updated in the current figure
image_data = getimage(gcf);%// image data stored into image_data variable
%// Open image_data on a separate figure window for verification.
%// Make sure this is the updated image.
figure,imshow(image_data)
How to use as a standalone code
Im = imread('cameraman.tif');%// This image is available in MATLAB image library.
h1 = imshow(Im)
h2 = imcontrast(gca); %// Perform imcontrast
waitfor(h2); %// Wait for figure data to be updated with imcontrast
image_data = getimage(gcf);%// Store modified image data
%// Show modified image data for verification
figure,imshow(image_data)
Upvotes: 1