Created
December 7, 2013 02:26
-
-
Save DarkSector/7836577 to your computer and use it in GitHub Desktop.
How to create those arrays!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| % get the position of the rectangle as well | |
| roiPosition = roiRect.getPosition(); | |
| %masked = createMask(roiRect, frame1); | |
| %imshow(frame1) | |
| % We will need | |
| global redArray; | |
| global greenArray; | |
| global blueArray; | |
| % figure(1); | |
| % subplot(1,3,1); | |
| % plot(red_channel); | |
| % | |
| % subplot(1,3,2); | |
| % plot(blue_channel); | |
| % | |
| % subplot(1,3,3); | |
| % plot(green_channel); | |
| for frame = 1:vidObj.NumberOfFrames-1045 | |
| % Take frame and apply mask | |
| % crop frame | |
| % separate frame into three different channels | |
| % append frame to individual channel array | |
| frame | |
| % create frame object | |
| frameObj = read(vidObj, frame); | |
| % create another rectangle from roiPosition | |
| % roiRect = imrect(frameObj, roiPosition); | |
| % Create the mask | |
| % roiMask = createMask(frameObj, roiPosition); | |
| roiMask = poly2mask(roiPosition(1), roiPosition(2), roiPosition(3), roiPosition(4)); | |
| % Apply the mask on all 3 dimensions/ all channels | |
| mask_3chan = repmat(roiMask, [1,1,3]); | |
| % Set all other pixels to 0 | |
| frameObj(~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 | |
| frameObj = imcrop(frameObj, roiPosition); | |
| red_channel = frameObj; | |
| blue_channel = frameObj; | |
| green_channel = frameObj; | |
| %extract the red channel | |
| red_channel = red_channel(:,:,1); | |
| %extract the green channel | |
| green_channel= green_channel(:,:,2); | |
| %extract the blue channel | |
| blue_channel= blue_channel(:,:,3); | |
| % if size(redArray) == 0 | |
| % % meaning the array is empty so it needs | |
| % % to be appended once | |
| % redArray = cat(3, red_channel); | |
| % elseif size(greenArray) == 0 | |
| % greenArray = cat(3, green_channel); | |
| % elseif size(blueArray) == 0 | |
| % blueArray = cat(3, blue_channel); | |
| % end | |
| redArray = cat(3, red_channel); | |
| greenArray = cat(3, green_channel); | |
| blueArray = cat(3, blue_channel); | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment