Hello, I am doing a project on background inpaint of video. I am not getting any hint of how to provide a mask as input along with video? Is it once the video is divided into different frames, mask is provided or before? If before, how do I mask object from a video? Kindly help me with this. I will be very thankful

 Réponse acceptée

Walter Roberson
Walter Roberson le 17 Fév 2018

0 votes

The only way to process videos in MATLAB is to read frames and process the frames. There is no way in MATLAB to process a video "directly" -- only frames that you read in from the video. The frames that you read from the video are just images.
Therefore you split the work:
  1. read a frame into an array -- a step that is independent of what you are going to do with the array
  2. process the array -- a step that is independent of how you input the array
  3. display or save the processed array -- a step that is independent of how you processed the array

13 commentaires

swathi
swathi le 21 Fév 2018
Sir thanks for the response. You made the point clear to me. I just started the work & I could successfully divide the video into frames, saved them in folder.From mathworks, I even got the code to mask object from frame using freehand. I need your help, during the course of my work if I find any problem. Thanks & regards
swathi
swathi le 23 Fév 2018
Sir, is it possible to display frame with mask applied to it, I dont want masked object to be displayed seperately, but it should be shown in different color in the image. Could you please help to do this?
The easiest approach is something like,
redMask = ones(size(YourMask));
redMask(:,:,[2 3]) = 0;
image( redMask );
hold on
image( YourImage, 'AlphaData', 1 - 0.2 * double(YourMask) );
hold off
axis image
What this does is first construct and display a solid red image. Then it displays your original image exactly on top of the solid red image, but with the AlphaData set so that in the positions that the mask is not set, the original image is completely opaque (shows only the original image), but in the positions that the mask is set, the original image is set to 20% transparent, so 20% of the red is mixed in with the original image there.
This process gives the selected locations a red tint without otherwise (much) altering their detail.
swathi
swathi le 24 Fév 2018
Thank you very much sir. I am looking for exactly this. But right now my matlab licence is expired. So I can only tell you if the code worked for me after 2 days. I am indeed very grateful to you.
swathi
swathi le 27 Fév 2018
Modifié(e) : Walter Roberson le 27 Fév 2018
Sir, I am facing some problem with the code. Can you please tell me whats wrong with the code below?
Image = imread('myimg.jpg');
imshow(Image, []);
axis on;
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Ask user to draw freehand mask.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand(); % Actual line of code to do the drawing.
Image1 = hFH.createMask();
xy = hFH.getPosition;
redMask = ones(size(Image1));
redMask(:,:,[2 3]) = 0;
image(redMask );
hold on
image( Image, 'AlphaData', 1 - 0.2 * double(redMask) );
hold off
axis image
Walter Roberson
Walter Roberson le 27 Fév 2018
What error are you seeing?
swathi
swathi le 27 Fév 2018
Sir I am getting this error: Error using image While setting the 'AlphaData' property of 'Image': Value must be a scalar, vector or array of numeric or logical type
swathi
swathi le 27 Fév 2018
And also can see this error in some executions: Error using imroi/parseInputsForCreateMask (line 95) Ambiguous syntax. Associated axes contains more than one image. Specify image handle as input argument to resolve ambiguity. Type "help imroi/createMask" for more information.
Error in imroi/createMask (line 256) [obj,h_im] = parseInputsForCreateMask(varargin{:});
I said
image( YourImage, 'AlphaData', 1 - 0.2 * double(YourMask) );
not
image( YourImage, 'AlphaData', 1 - 0.2 * double(RedMask) );
In your code, YourMask is Image1:
image( YourImage, 'AlphaData', 1 - 0.2 * double(Image1) );
For the other problem, change
imshow(Image, []);
to
imh = imshow(Image, []);
and change
hFH = imfreehand(); % Actual line of code to do the drawing.
to
hFH = imfreehand(imh); % Actual line of code to do the drawing.
swathi
swathi le 1 Mar 2018
Thank you sir. It works. I am very grateful to you that you took time to sort out my problem.
swathi
swathi le 1 Mar 2018
Sir, I have chosen the "background inpainting in videos" topic. But I am having little confusions regarding its working. Once we give Video & mask as input, next step is frame alignment. the work requires to use Ransac algorithm. Can you guide me how to proceed further? Now I have selected 1 frame & applied mask. I am stuck here. Need little more help,please guide me.
Walter Roberson
Walter Roberson le 1 Mar 2018
I am not familiar with Ransac
swathi
swathi le 2 Mar 2018
Ok thank you sir

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by