%%%%%%%%%%%% ENEE 631 HOMEWORK #6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Motion compensation analysis using exhaustive search and the fast 3-STEP % search algorithm. % % This script uses 8x8 macroblocks and the search range is set to 3, 7 and % 15. The motion in the video sequenece (Flower Garden) is global (camera % motion). For each algorithm and search range we compute the energy of the % residual image and the entropy of the resulting Motion Vectors (with DPCM % encoding). % % Programmed by Daniel Garcia-Romero 4-24-2006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Load images and only keep the Y channel %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Seq_images=zeros(240,360,5); for i=1:5, I_name=sprintf('flower%d.bmp', i); temp_I=imread(I_name); temp_I=rgb2ycbcr(temp_I); %imshow(temp_I(:,:,1)); %pause; Seq_images(:,:,i)=double(temp_I(:,:,1)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Allocate memory for results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Error images for the EBMA algorithm with different search ranges (3,7,15) Error_I_EBMA_R_3=zeros(240,360,4); Error_I_EBMA_R_7=zeros(240,360,4); Error_I_EBMA_R_15=zeros(240,360,4); %Error images for the 3-STEP algorithm with different search ranges (3,7,15) Error_I_3_STEP_R_7=zeros(240,360,4); Error_I_3_STEP_R_15=zeros(240,360,4); %MC images for the EBMA algorithm with different search ranges (3,7,15) MC_I_EBMA_R_3=zeros(240,360,4); MC_I_EBMA_R_7=zeros(240,360,4); MC_I_EBMA_R_15=zeros(240,360,4); %MC images for the 3-STEP algorithm with different search ranges (3,7,15) MC_I_3_STEP_R_7=zeros(240,360,4); MC_I_3_STEP_R_15=zeros(240,360,4); %Motion vectors assuming 8x8 block size MV_EBMA_R_3=zeros(240*360/64,2,4); %Rows=number of blocks, Columns=2 (x coordinate, y coordiante) MV_EBMA_R_7=zeros(240*360/64,2,4); %Rows=number of blocks, Columns=2 (x coordinate, y coordiante) MV_EBMA_R_15=zeros(240*360/64,2,4); %Rows=number of blocks, Columns=2 (x coordinate, y coordiante) MV_3_STEP_R_7=zeros(240*360/64,2,4); %Rows=number of blocks, Columns=2 (x coordinate, y coordiante) MV_3_STEP_R_15=zeros(240*360/64,2,4); %Rows=number of blocks, Columns=2 (x coordinate, y coordiante) %Processing time for each configuration PT_EBMA_R_3=zeros(4,1); PT_EBMA_R_7=zeros(4,1); PT_EBMA_R_15=zeros(4,1); PT_3_STEP_R_7=zeros(4,1); PT_3_STEP_R_15=zeros(4,1); %MV entropy for each configuration Entrpoy_EBMA_R_3=zeros(4,1); Entrpoy_EBMA_R_7=zeros(4,1); Entrpoy_EBMA_R_15=zeros(4,1); Entrpoy_3_STEP_R_7=zeros(4,1); Entrpoy_3_STEP_R_15=zeros(4,1); %Energy for each configuration Energy_EBMA_R_3=zeros(4,1); Energy_EBMA_R_7=zeros(4,1); Energy_EBMA_R_15=zeros(4,1); Energy_3_STEP_R_7=zeros(4,1); Energy_3_STEP_R_15=zeros(4,1); %Energy original image Energy_original_I=zeros(4,1); %Energy diff image (Without MC) Energy_diff_I=zeros(4,1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Compute motion estimation and compensation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % RANGE = 3 for i=2:5 %Only compute 4 difference images out of the 5 frames Range=3; %EBMA t0=clock; [Error_I_EBMA_R_3(:,:,i-1),MC_I_EBMA_R_3(:,:,i-1),MV_EBMA_R_3(:,:,i-1)]=my_EBMA(Seq_images(:,:,i-1),Seq_images(:,:,i),Range); PT_EBMA_R_3(i-1)=etime(clock,t0); %Compute entropy Entrpoy_EBMA_R_3((i-1))=my_MV_entropy(MV_EBMA_R_3(:,:,i-1),64,Range); %Compute Energy Energy_EBMA_R_3(i-1)=10*log10(sum(sum(Error_I_EBMA_R_3(:,:,i-1).^2))); %Only compute this once Energy_original_I(i-1)=10*log10(sum(sum(Seq_images(:,:,i).^2))); Energy_diff_I(i-1)=10*log10(sum(sum((Seq_images(:,:,i)-Seq_images(:,:,i-1)).^2))); end % RANGE = 7 for i=2:5 %Only compute 4 difference images out of the 5 frames Range=7; t0=clock; [Error_I_EBMA_R_7(:,:,i-1),MC_I_EBMA_R_7(:,:,i-1),MV_EBMA_R_7(:,:,i-1)]=my_EBMA(Seq_images(:,:,i-1),Seq_images(:,:,i),Range); PT_EBMA_R_7(i-1)=etime(clock,t0); %Compute entropy [Entrpoy_EBMA_R_7((i-1))]=my_MV_entropy(MV_EBMA_R_7(:,:,i-1),64,Range); %Compute Energy Energy_EBMA_R_7(i-1)=10*log10(sum(sum(Error_I_EBMA_R_7(:,:,i-1).^2))); t0=clock; [Error_I_3_STEP_R_7(:,:,i-1),MC_I_3_STEP_R_7(:,:,i-1),MV_3_STEP_R_7(:,:,i-1)]=my_3_STEP_search(Seq_images(:,:,i-1),Seq_images(:,:,i),Range); PT_3_STEP_R_7(i-1)=etime(clock,t0); %Compute entropy [Entrpoy_3_STEP_R_7((i-1))]=my_MV_entropy(MV_3_STEP_R_7(:,:,i-1),64,Range); %Compute Energy Energy_3_STEP_R_7(i-1)=10*log10(sum(sum(Error_I_3_STEP_R_7(:,:,i-1).^2))); end % RANGE = 15 for i=2:5 %Only compute 4 difference images out of the 5 frames Range=15; t0=clock; [Error_I_EBMA_R_15(:,:,i-1),MC_I_EBMA_R_15(:,:,i-1),MV_EBMA_R_15(:,:,i-1)]=my_EBMA(Seq_images(:,:,i-1),Seq_images(:,:,i),Range); PT_EBMA_R_15(i-1)=etime(clock,t0); %Compute entropy [Entrpoy_EBMA_R_15((i-1))]=my_MV_entropy(MV_EBMA_R_15(:,:,i-1),64,Range); %Compute Energy Energy_EBMA_R_15(i-1)=10*log10(sum(sum(Error_I_EBMA_R_15(:,:,i-1).^2))); t0=clock; [Error_I_3_STEP_R_15(:,:,i-1),MC_I_3_STEP_R_15(:,:,i-1),MV_3_STEP_R_15(:,:,i-1)]=my_3_STEP_search(Seq_images(:,:,i-1),Seq_images(:,:,i),Range); PT_3_STEP_R_15(i-1)=etime(clock,t0); [Entrpoy_3_STEP_R_15((i-1))]=my_MV_entropy(MV_3_STEP_R_15(:,:,i-1),64,Range); %Compute Energy Energy_3_STEP_R_15(i-1)=10*log10(sum(sum(Error_I_3_STEP_R_15(:,:,i-1).^2))); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Show images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i=1:4 figure; colormap gray; subplot(2,2,1); imagesc(Seq_images(:,:,i+1)); subplot(2,2,2); imagesc(Seq_images(:,:,i+1)-Seq_images(:,:,i)); subplot(2,2,3); imagesc(MC_I_EBMA_R_7(:,:,i)); subplot(2,2,4); imagesc(Error_I_EBMA_R_7(:,:,i)); end