www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I2_08_2_ROI.m
%% 娭怱椞堟(ROI)偺巜掕偲憖嶌 clear;clc;close all;imtool close all %% 夋憸撉傒崬傒 figure im = imread('peppers.png'); imshow(im) %% 偝傑偞傑側ROI巜掕 h1 = drawellipse('Center',[127 174],'SemiAxes',[56 24],'RotationAngle',27); h2 = drawcircle('Center',[152 278],'Radius',30,'Color','red'); h3 = drawfreehand('Position',[86 278;50 262;16 270;5 306;19 340;47 357;80 343;97 312],'Color','yellow'); h5 = drawline('Position',[235 226; 268 237],'Color','green'); h6 = drawpoint('Position',[334 225],'Color','magenta'); h7 = drawpolygon('Position',[448 227;419 308; 509 305],'Color','cyan'); h8 = drawpolyline('Position',[101 383;103 306;406 293],'Color','blue'); h9 = drawrectangle('Position',[185 78 79 54],'Color','white'); shg; %% 傾僔僗僩晅偒偺僼儕乕僴儞僪偱揔摉側椞堟傪埻傓 h = drawassisted(); %% 儅僗僋惗惉 bw = createMask(h); figure, imshow(bw); %% 惗惉偟偨儅僗僋傪傾儖僼傽儅僗僋偲偟偰僈僀僪僼傿儖僞乕傪偐偗傞 alphamat = imguidedfilter(single(bw),im,'DegreeOfSmoothing',2); figure, imshow(alphamat); %% 揔梡懳徾偺夋憸傪撉傒崬傒丄儕僒僀僘 target = imread('fabric.png'); alphamat = imresize(alphamat,[size(target,1),size(target,2)]); im = imresize(im, [size(target,1), size(target,2)]); figure, imshowpair(im,target,'montage'); %% 傾儖僼傽僽儗儞僪 fused = single(im).*alphamat + (1-alphamat).*single(target); fused = uint8(fused); figure, imshow(fused); shg; %% 儅僗僋夋憸偺帠慜掕媊 h = 150; % 惗惉偡傞儅僗僋偺崅偝 w = 250; % 惗惉偡傞儅僗僋偺暆 BW = false(h,w); figure, imshow(BW); %% drawpolygon偱ROI巜掕 x = [116 194 157 112 117]; y = [ 34 72 105 99 34]; hPolygon = drawpolygon('Position',[x' y']); shg; %% roipoly()偱儅僗僋惗惉 BW = roipoly(h, w, x, y); figure; imshow(BW); %% poly2mask()偱儅僗僋惗惉 BW = poly2mask(x, y, h, w); figure; imshow(BW); %% 懭墌宍偺ROI巜掕 BW = false(150, 250); % 惗惉偡傞儅僗僋偲摨偠僒僀僘 figure; h_im = imshow(BW); position = [55 20 150 100]; % [xmin ymin width height] e = drawellipse(gca, 'Center',position(1:2)+position(3:4)/2,... 'SemiAxes',position(3:4)/2); shg; %% 懭墌宍偺ROI偐傜儅僗僋惗惉 BW = createMask(e, h_im); figure, imshow(BW); %% 3D偺僉儏乕儃僀僪(捈曽懱)偱偺ROI巜掕 load seamount figure; hScatter = scatter3(x,y,z); hCuboid = drawcuboid(hScatter); %% % Copyright 2018 The MathWorks, Inc.