www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱源码程序matlab > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I2_06_3_myImregdemons.m
%% 旕崉懱偺儗僕僗僩儗乕僔儑儞 (2師尦丒3師尦偺僌儗乕僗働乕儖夋憸) clear;clc;close all;imtool close all; %% 俀偮偺夋憸偺撉崬傒 fixed = imread('hands1.jpg'); % 埵抲崌偣偺僞乕僎僢僩 moving = imread('I2_06_3_hands2a.jpg'); figure;imshow([fixed, moving]); %% 僌儗乕僗働乕儖傊曄姺d偹偰昞帵 fixed = rgb2gray(fixed); moving = rgb2gray(moving); figure;imshowpair(fixed,moving); %% 僌儗乕僗働乕儖傪暲傋偰昞帵 figure;subplot(2,1,1); imshow([fixed, moving]); %% [慜張棟] 僸僗僩僌儔儉儅僢僠儞僌傪梡偄偰丄婸搙偺嵎傪曗惓 moving = imhistmatch(moving,fixed); subplot(2,1,2); imshow([fixed, moving]); %% 曄埵応峴楍傪媮傔傞 乮fixed忋偺奺僺僋僙儖枅偺丄X,Y曽岦偺曄埵乯 D = imregdemons(moving, fixed, [500 400 200]); %斀暅夞悢丗500夞(掅夝憸搙), 400夞, 300夞(崅夝憸搙) %% 曄埵偺壜帇壔 flow = opticalFlow(D(:,:,1), D(:,:,2)); figure;imshow(fixed); hold on plot(flow,'DecimationFactor',[10 10],'ScaleFactor',1); shg; hold off %% 婔壗妛揑曄姺丒昞帵 movingReg = imwarp(moving, D); figure;imshow([moving, movingReg]); title('婔壗妛揑曄姺偺慜屻', 'FontSize', 16); %% 埵抲崌偣偺僞乕僎僢僩夋憸偲廳偹偰昞帵 figure;imshowpair(fixed, movingReg); %% 廔椆 %% 僔儞僾儖側恾宍偱偺張棟 fixed = zeros(100); moving = fixed; fixed(50:59, 30:39)=1; fixed(50:59, 55:64)=1; moving(50:59, 30:39)=1; moving(50:59, 45:54)=1; % 塃偵10僺僋僙儖堏摦 figure; subplot(1,2,1); imshow(fixed); subplot(1,2,2); imshow(moving); shg; figure;imshowpair(fixed, moving); % D = imregdemons(moving, fixed, [500 400 200], 'AccumulatedFieldSmoothing',0.5); %斀暅夞悢丗500夞(掅夝憸搙), 400夞, 300夞(崅夝憸搙) % 婔壗妛揑曄姺丒昞帵 movingReg = imwarp(moving, D); imtool(movingReg); figure;imshowpair(fixed, movingReg); % 傎傏堦抳偟偰偄傞 %% 曄埵応偺壜帇壔 flow = opticalFlow(D(:,:,1), D(:,:,2)); figure;imshow(moving); hold on plot(flow,'DecimationFactor',[5 5],'ScaleFactor',1); shg; hold off %% 曄埵応偺抣偺妋擣 D(55, 30:69, 1) % D偺抣丗fixed偺懳墳偡傞揰偺堏摦 %% 嶲峫丗hands2a.jpg 偺惗惉僗僋儕僾僩 I = imread('hands2.jpg'); ycbcr = rgb2ycbcr(I); ycbcr(:,:,1) = ycbcr(:,:,1)*0.8; I1 = ycbcr2rgb(ycbcr); imwrite(I1, 'I2_06_2_hands2a.jpg'); %% Copyright 2014 The MathWorks, Inc.