I'm trying to use matlab to directly alter the contrast of an stock image with just the imcontrast figure. and link my contrast adjustments to the imadjust function. This way, I can automatically adjust contrast in an image without having to write any numbers down or save an image. I use the Closerequestfunc to trigger a function that records the final contrast values on the slider when I close out of the contrast figure. My trouble is that I cannot figure out a way to use the the final variables (the windowclose_min ; windowclose_max) in my function outside of the function unless I make them global variables. Pls Help!
Note!!! Do not hit "Adjust Data" in the imcontrast figure, just adjust the bars and close.
I = imread('pout.tif') imshow(I) imcontrast; F = imcontrast(gcf); window_min = str2double(get(findobj(F, 'tag', 'window min edit'), 'String')); window_max = str2double(get(findobj(F, 'tag', 'window max edit'), 'String')); disp(window_min) %toggle on and off at will
disp(window_max) %toggle on and off at will set(F, 'CloseRequestFcn', @(s,e)getValues(s)); %This function still confuses me. I do not know what the s or e represent.
uiwait %activates once you close out of the first image (I)
G = imadjust(I,[closewindow_min/window_max closewindow_max/window_max],[0 1]); imshowpair(I,G,'Montage')function getValues(F) global closewindow_min global closewindow_max closewindow_min = str2double(get(findobj(F, 'tag', 'window min edit'), 'String')); closewindow_max = str2double(get(findobj(F, 'tag', 'window max edit'), 'String')); disp(closewindow_min); disp(closewindow_max); delete(F) %This is the only way I could figure out how to close the imcontrast figure
end
Best Answer