我正在建立一个图像分析图形界面在matlab中,在其中的一点,图像的对比度可以修改使用imcontrast工具。接下来,我想将此对比度设置自动应用于其他图像,这在imshow(image, [min_value max_value])中是可能的。因此,我想返回我的程序,从min_value工具返回这些max_value和imcontrast (见下图)。有什么建议可以让我自动得到这些值吗?

发布于 2016-08-23 12:31:50
您可以使用由figure返回的imcontrast句柄来查找包含窗口限制的uicontrols。您可以使用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发布于 2016-10-03 19:05:26
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);
endhttps://stackoverflow.com/questions/39100499
复制相似问题