Wednesday, 28 August 2013

Creating a circular mask for my graph

Creating a circular mask for my graph

I'm plotting a square image, but since my camera views out of a circular
construction, I want the image to look circular as well. So to do this, I
just wanted to create a mask for the image (basically create a matrix, and
multiply my data by the mask, so if I want to retain my image I am
multiplying by one, and if I want that part of the image to go to black, I
multiply by 0).
I'm not sure the best way to make a matrix that will represent a circular
opening though. I just want every element within the circle to be a "1"
and every element outside the circle to be a "0" so I can color my image
accordingly. I was thinking of doing a for loop, but I was hoping there
was a faster way to do it. So...all I need is:
A matrix that is 1280x720
I need a circle that has a diameter of 720, centered in the middle of the
1280x720 matrix (what I mean by this is all elements corresponding to
being within the circle have a "1" and all other elements have a "0"
My attempt
mask = zeros(1280,720)
for i = 1:1280
for j = 1:720
if i + j > 640 && i + j < 1360
mask(i,j) = 1;
end
end
end
Well the above obviously doesn't work, I need to look at it a little
better to form a better equation for determing when to add a 1 =P but
ideally I would like to not use a for loop
Thanks, let me know if anything is unclear!

No comments:

Post a Comment