matlab - Creating a circular mask for my graph -
i'm plotting square image, since camera views out of circular construction, want image circular well. this, wanted create mask image (basically create matrix, , multiply data mask, if want retain image multiplying one, , if want part of image go black, multiply 0).
i'm not sure best way make matrix represent circular opening though. want every element within circle "1" , every element outside circle "0" can color image accordingly. thinking of doing loop, hoping there faster way it. so...all need is:
- a matrix 1280x720
- i need circle has diameter of 720, centered in middle of 1280x720 matrix (what mean elements corresponding being within circle have "1" , other elements have "0"
my attempt
mask = zeros(1280,720) = 1:1280 j = 1:720 if + j > 640 && + j < 1360 mask(i,j) = 1; end end end
well above doesn't work, need @ little better form better equation determing when add 1 =p ideally not use loop
thanks, let me know if unclear!
@kol 's answer looks correct. can vectorized code using meshgrid function.
width = 1280; height = 720; radius = 360; centerw = width/2; centerh = height/2; [w,h] = meshgrid(1:width,1:height); mask = ((w-centerw).^2 + (h-centerh).^2) < radius^2;
Comments
Post a Comment