如何获得matlab imcontrast工具的最小值和最大值?

How to get minimum and maximum value of matlab imcontrast tool?

我正在 matlab 中构建一个图像分析 GUI,在某一时刻,可以使用 imcontrast 工具修改图像的对比度。接下来,我想自动将此对比度设置应用于其他图像,这可以通过 imshow(image, [min_value max_value]) 实现。因此,我想 return 我的程序 return 这些 min_valuemax_value 来自 imcontrast 工具(见下图)。有什么建议可以自动获取这些值吗?

您可以使用 imcontrast 返回的 figure 句柄来查找包含 Window 限制的 uicontrol。您可以使用 Tag 名称检索编辑框句柄,检索 String 属性 并使用 str2double.

将其转换为数字
hfig = imcontrast(gca);
window_min = str2double(get(findobj(hfig, 'tag', 'window min edit'), 'String'));
window_max = str2double(get(findobj(hfig, 'tag', 'window max edit'), 'String'));

附带说明一下,我发现标签名称的方式是使用以下内容,在 2014b+ 中您会在括号中看到标签名称:

findobj(hfig, 'style', 'edit')

%   UIControl    (max data range edit)
%   UIControl    (min data range edit)
%   UIControl    (outlier percent edit)
%   UIControl    (window center edit)
%   UIControl    (window width edit)
%   UIControl    (window max edit)
%   UIControl    (window min edit)

标签名称似乎至少自 R2008a 以来就没有更改过。

更新

如果要在关闭时获取值,可以使用图的CloseRequestFcn回调调用自定义函数来检索这些值。

set(hfig, 'CloseRequestFcn', @(s,e)getValues(s))

function getValues(hfig)
    window_min = str2double(get(findobj(hfig, 'tag', 'window min edit'), 'String'));
    window_max = str2double(get(findobj(hfig, 'tag', 'window max edit'), 'String'));
end
Here is the code I have for this:

close all
clear all
I=imread('pout.tif');
imshow(I);

%--------------
ifig = gcf; % Change here
%--------------

hfig_imcontrast = imcontrast(gca);

set(hfig_imcontrast, 'CloseRequestFcn', @(s,e)getValues(s))
%--------------
set(ifig, 'CloseRequestFcn', @(s,e)closeFig(s,hfig_imcontrast)) % Change here

findall(hfig_imcontrast)
uiwait(hfig_imcontrast)

window_min
window_max

I_bit_depth = class(I);
I_colormap = gray(double(intmax(I_bit_depth)));
imshow(imadjust(I,[I_colormap(window_min);I_colormap(window_max)],[]));

%%%%%%%%%%%%%%%
function closeFig(hfig,ifig)
close(ifig);
close(hfig);
end

%%%%%%%%%%%%%%%%
function getValues(hfig)
    window_min = str2double(get(findobj(hfig, 'tag', 'window min edit'), 'String'));
    window_max = str2double(get(findobj(hfig, 'tag', 'window max edit'), 'String'));

    assignin('base', 'window_min', window_min);
    assignin('base', 'window_max', window_max);
end