【问题标题】:How to read the image data from particular axes of MATLAB GUI?如何从 MATLAB GUI 的特定轴读取图像数据?
【发布时间】:2014-07-05 22:45:15
【问题描述】:

我设计了一个 MATLAB GUI,其中有两个轴用于显示图像。我正在使用“不对比度”功能来调整第一轴上图像的亮度/对比度。现在,我想将这个增强的输出(亮度/对比度调整后的输出)存储在某个变量中。由于'imcontrast'函数不返回输出图像,所以我怎样才能得到输出图像?或者有没有办法从特定轴读取图像数据?我曾尝试使用“getimage”函数,但它返回包含在 Handle Graphics 对象中的第一个图像数据(即先前显示的输入图像),而不是最新的亮度/对比度调整图像。请帮我保存由“反差”功能提供的亮度/对比度调整图像。

【问题讨论】:

    标签: matlab user-interface matlab-guide axes contrast


    【解决方案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)
    

    【讨论】:

    • 感谢您帮助我。但是,它不起作用。即使在添加 waitfor(gcf) (如您所建议的那样)之后,getimage 仍会返回先前显示的输入图像。请帮我做一些其他的选择。
    • @Vikrant 对我有用,你能再试一次吗?也许关闭 MATLAB 并重新启动 GUI?
    • 我尝试重新启动 MATLAB,并尝试将这几行写入单独的 matlab 文件中。 Im = imread('cameraman.tif');显示(我);反差(gca); %// 执行反差 waitfor(gcf); %// 等待用imcontrast 更新图形数据 image_data = getimage(gcf);%// 将图像数据存储为 image_data 变量 imshow(image_data);但是,它在 image_data 变量中返回空矩阵。我已经调整了对比度,然后关闭了执行不对比度时弹出的“调整对比度”窗口。我什至尝试在“调整数据”窗口中点击调整数据,但没有成功
    • @Vikrant 请查看刚刚添加的如何在 GUI 中使用如何作为独立代码使用 部分。希望这能解决它!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 2014-02-13
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    相关资源
    最近更新 更多