When the correlation coefficient calculated falls below a threshold, a ‘1’ will be stored in the map array.
Figure 1. map.jpg
Figure 2. map1.jpg
Figure 1 - Mapping image of human bodies after correlation Figure 2 - Mapping image of human bodies after removing small clusters
Figure 3. map2.jpg – Mapping matrix after applying median filter Multiplying the mapping matrix (map2.jpg) with the original image with humans yields the result (output.jpg)
Figure 4. output.jpg – Final Result
Appendix - Matlab Code clear all; clc; imgNoHuman = imread('IMG_2699_Back.bmp'); imgHuman = imread('IMG_2699.bmp'); figure; subplot(2,2,1); imshow(imgNoHuman) subplot(2,2,2); imshow(imgHuman) [x y z] = size(imgNoHuman); f1 = rgb2gray(imgNoHuman); f2 = rgb2gray(imgHuman); imwrite(f1, 'f1.jpg'); imwrite(f2, 'f2.jpg'); g1 = double(f1(:,:,1)); g2 = double(f2(:,:,1)); corr2(g1,g2); map = zeros(x,y); cor = zeros(x,y); % determine correlation of the 2 images const = 1; i = 1+const; j = 1+const; % calculate the correlation of each pixel (size of 3x3 matrix is used) while i <= x-const, j = 1+const; while j <= y-const, h1 = g1(i-const:i+const,j-const:j+const); h2 = g2(i-const:i+const,j-const:j+const); cor(i,j) = corr2(h1,h2); % cor(i-const:i,j-const:j) = corr2(h1,h2); if cor(i,j) < 0.45 map(i,j) = 1; end j = j+const; end i = i+const; end figure;imshow(map); imwrite(map, 'map.jpg'); map1 = bwareaopen(map, 240); imwrite(map1, 'map1.jpg'); % median filter applied to remove salt and pepper noise in map1 array map2 = medfilt2(map1,[10,10]); figure;imshow(map2) imwrite(map2, 'map2.jpg'); % multiply map with original image to get original colour output(:,:,1) = double(imgHuman(:,:,1)) .* map2; output(:,:,2) = double(imgHuman(:,:,2)) .* map2; output(:,:,3) = double(imgHuman(:,:,3)) .* map2;
% fill background with the colour white for i = 1:1:x for j = 1:1:y if map2(i,j) == 0 output(i,j,1:3) = [255, 255, 255]; end end end imwrite(uint8(output),'output.jpg'); figure;imshow(uint8(output))