2016-08-23 195 views
0

我正在matlab中構建一個圖像分析圖形用戶界面,其中在一個點上,可以使用imcontrast工具修改圖像的對比度。接下來,我想自動將此對比度設置應用於其他圖像,這可以使用imshow(image, [min_value max_value])。因此,我想返回我的程序以從imcontrast工具返回這些min_valuemax_value(請參閱下圖)。任何建議如何我可以自動獲得這些值? enter image description here如何獲得matlab imcontrast工具的最小值和最大值?

回答

1

您可以使用imcontrast返回的figure句柄來查找包含窗口限制的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 
+0

謝謝你,這有很大幫助!但是,當我手動更改工具中的限制時,這些值不會更新。所以我需要知道數字關閉時的值。任何建議如何實現這一目標? – sdbonte

+0

我現在只是插入一個'while'循環,如果'imcontrast'工具的句柄仍然存在並且更新值,則每循環0.01秒檢查一次。可能有更優雅的解決方案。 – sdbonte

+1

@sdbonte更新了一個如何攔截數字的例子 – Suever

0
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 
相關問題