Skip to content

Instantly share code, notes, and snippets.

@DarkSector
Last active December 30, 2015 12:39
Show Gist options
  • Select an option

  • Save DarkSector/7830112 to your computer and use it in GitHub Desktop.

Select an option

Save DarkSector/7830112 to your computer and use it in GitHub Desktop.
Matlab video manipulation
clc;
clear;
% Start with importing the video
vidObj = VideoReader('/Users/DarkSector/Desktop/vid.avi');
% Once loaded lets get the first frame and choose an ROI on it
frame1 = read(vidObj, 1);
%now let's show the image and select the ROI on it
imshow(frame1)
roiRect = imrect;
roiPosition = roiRect.getPosition();
roiMask = createMask(roiRect);
%masked = createMask(roiRect, frame1);
mask_3chan = repmat(roiMask, [1,1,3]);
frame1(~mask_3chan) = 0;
% if we are not using the rest of the pixels, might as well remove
% them and crop the image.
% No reason to store dummy data
frame1 = imcrop(frame1, roiPosition);
%imshow(frame1)
red_channel = frame1;
red_channel(:,:,2) = 0;
red_channel(:,:,3) = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment