How to centering an Silhouette image

Hello.
I wanna centering an image (image 1 to image 2)
image 1 image 2
I got the image 1 from this code.
clear all
close all
%// read the video:
reader = VideoReader('lena_side.avi');
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4);
%// estimate foreground as deviation from estimated background:
fIdx = 40; %// do it for frame 43
fg1 = sum( abs( vid{fIdx} - bg ), 3 ) > 0.25;
figure;
subplot(141); imshow( bg );
subplot(142); imshow( fg1 );

 Accepted Answer

Hi
The image is gray scale with one object and the object is present in the right half of the image, so the usual approch could be to find the centroid of the object and shift the centroid of the object to the center of new image. New image should be the image consisting of zeros with same size of previous image.

5 Comments

Hello. Thank you for reply.
Can you explain how to find the centroid of the object?
Hi
You can use regionprops function on that image, it will give the centroid, Area and other information of the connected components. Since the object is having large area, take the centroid location corresponding to maximum area. For more information, you can visit the documentation link.
Hope it will help.
Thank you so much.
I want to use video as input.
In that cases, could you give an idea to use regionprops at this code.
Since I make video to matrix, I don't know how to use regionprops,
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
en.
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4);
%// estimate foreground as deviation from estimated background:
for i=1:100
fIdx(i) = i; %// do it for frame 1 ~ 60
fg{i} = sum( abs( vid{fIdx(i)} - bg ), 3 );
fg{i} = imresize(fg{i}, 0.2);
fg{i} = reshape(fg{i},[],1);
end
X = cell2mat(fg);
data = double(X);
Mahesh Taparia
Mahesh Taparia on 18 Mar 2020
Edited: Mahesh Taparia on 18 Mar 2020
Hi
You can use the regionprops function on each frame, i.e in the for loop and do the necessary computation there. Save the resultant frame inside the loop.
Thank you so much.
I found the solution
However, I don't know how to use this in folders of images.

Sign in to comment.

More Answers (0)

Asked:

on 11 Mar 2020

Commented:

on 18 Mar 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!