
https://kr.mathworks.com/help/matlab/creating_guis/image-histogram-gui-in-app-designer.html
여러 개의 좌표축을 사용하여 이미지 분석의 결과를 표시하는 앱 만들기 - MATLAB & Simulink - MathWorks
이 예제의 수정된 버전이 있습니다. 사용자가 편집한 내용을 반영하여 이 예제를 여시겠습니까?
kr.mathworks.com
핵심코드
1) methods (Access = Private)
1-1)
function updateImage(app,imagefile) % For corn.tif, read the second image in the file if strcmp(imagefile,'corn.tif') im = imread("corn.tif", 2); else try im = imread(imagefile); catch ME % If problem reading image, display error message uialert(app.UIFigure,ME.message,"Image Error"); return; end end % Create histograms based on number of color channels switch size(im,3) case 1 % Display the grayscale image imagesc(app.ImageAxes,im); % Plot all histograms with the same data for grayscale histr = histogram(app.RedAxes,im,"FaceColor",[1 0 0],"EdgeColor","none"); histg = histogram(app.GreenAxes,im,"FaceColor",[0 1 0],"EdgeColor","none"); histb = histogram(app.BlueAxes,im,"FaceColor",[0 0 1],"EdgeColor","none"); case 3 % Display the truecolor image imagesc(app.ImageAxes,im); % Plot the histograms histr = histogram(app.RedAxes,im(:,:,1),"FaceColor",[1 0 0],"EdgeColor","none"); histg = histogram(app.GreenAxes,im(:,:,2),"FaceColor",[0 1 0],"EdgeColor","none"); histb = histogram(app.BlueAxes,im(:,:,3),"FaceColor",[0 0 1],"EdgeColor","none"); otherwise % Error when image is not grayscale or truecolor uialert(app.UIFigure,"Image must be grayscale or truecolor.","Image Error"); return; end % Get largest bin count maxr = max(histr.BinCounts); maxg = max(histg.BinCounts); maxb = max(histb.BinCounts); maxcount = max([maxr maxg maxb]); % Set y axes limits based on largest bin count app.RedAxes.YLim = [0 maxcount]; app.RedAxes.YTick = round([0 maxcount/2 maxcount],2,"significant"); app.GreenAxes.YLim = [0 maxcount]; app.GreenAxes.YTick = round([0 maxcount/2 maxcount],2,"significant"); app.BlueAxes.YLim = [0 maxcount]; app.BlueAxes.YTick = round([0 maxcount/2 maxcount],2,"significant"); end |
2) Callback Function
2-1) 앱이 시작될 때 데이터 로딩 및 초기화를 수행하는 기능
function startupFcn(app) % Configure image axes app.ImageAxes.Visible = "off"; app.ImageAxes.Colormap = gray(256); axis(app.ImageAxes,"image"); % Update the image and histograms updateImage(app,"peppers.png"); end |
2-2)
function DropDownValueChanged(app, event) updateImage(app,app.DropDown.Value); end |
2-3)
function LoadCustomImageButtonPushed(app, event) % Display uigetfile dialog filterspec = {'*.jpg;*.tif;*.png;*.gif','All Image Files'}; [file, path] = uigetfile(filterspec); % Make sure user didn't cancel uigetfile dialog if (ischar(path)) fname = [path file]; updateImage(app,fname); end end |