How to use image segmentation in video images of folders
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kong
el 17 de Mzo. de 2020
Hello.
I have several videos. After convert videos to binary images, I want to convert binary images to centered images(cropped).
Binary images ---> cropped image


1.I will use this code to convert video to binary images.
clear all
close all
%// read the video:
reader = VideoReader('person01_boxing_d1_uncomp.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:
for i=1:40
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);
2. And then I want to convert binary images to centered image(cropped) using image segmentation
Please let me know how to use these codes when I use several videos as input.
I attached sample video.
message = sprintf('Would you like to crop out each coin to individual images?');
reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
% Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
if strcmpi(reply, 'Yes')
figure; % Create a new figure window.
% Maximize the figure window.
set(gcf, 'Units','Normalized','OuterPosition',[0 0 1 1]);
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this coin into it's own image.
subImage = imcrop(originalImage, thisBlobsBoundingBox);
% Determine if it's a dime (small) or a nickel (large coin).
if blobMeasurements(k).Area > 2200
coinType = 'nickel';
else
coinType = 'dime';
end
% Display the image with informative caption.
subplot(3, 4, k);
imshow(subImage);
caption = sprintf('Coin #%d is a %s.\nDiameter = %.1f pixels\nArea = %d pixels', ...
k, coinType, blobECD(k), blobMeasurements(k).Area);
title(caption, 'FontSize', textFontSize);
end
0 comentarios
Respuesta aceptada
Image Analyst
el 18 de Mzo. de 2020
Put your code for one video file inside the loop over all video files. It might be best to put it all inside a function that takes the video filename.
9 comentarios
Image Analyst
el 19 de Mzo. de 2020
That was your variable. Remember when you had
%// read the video:
list = dir('*.avi')
but now you decided not to use it anymore. It's also a built-in function in a toolbox that you don't have so it's warning you about that. I suggest you use another name like fileList instead.
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Preview and Device Configuration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!