Here's the code to create a greyscale circle shaped mask with a center at (x,y) and a radius of r in Matlab:
main.m295 chars15 lines
In the code above, we create a grid of coordinates using the ndgrid
function for the x and y coordinates. We then create a Boolean mask of pixels where their distance to the center of the circle is less than or equal to the radius. The uint8
function is used to convert the values in the mask to 8-bit unsigned integer values for displaying the greyscale values of the image. Finally, the repmat
function repeats the mask along the third dimension to make it a 3-channel image, with each channel containing the same mask. The output is then displayed using the imshow
function.
gistlibby LogSnag