我设计了一个MATLAB GUI,其中有两个轴用于显示图像。我正在使用' imcontrast'用于调整第一轴上图像的亮度/对比度的功能。现在,我想将这个增强的输出(亮度/对比度调整输出)存储在某个变量中。作为' imcontrast'函数不返回输出图像,那么如何获得输出图像?或者有没有办法从特定轴读取图像数据?我曾试过过' getimage'功能但它返回Handle Graphics对象中包含的第一个图像数据(即先前显示的输入图像)而不是最新的亮度/对比度调整图像。请帮助我保存亮度/对比度调整后的图像,由“对比”提供。功能
答案 0 :(得分:1)
使用此 -
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
如何在GUI中使用
为了展示如何使用它,您可以使用MATLAB-Guide创建一个按钮,并在其中使用回调函数 -
%// 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)
如何用作独立代码
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)