Explanation on how to make a circle
Mostra commenti meno recenti
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
Can someone just explain to me this part:
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
I just want to further understand the whole code. If it's not too much, explanation of the whole code will be more appreciated. Thanks a lot!
3 Commenti
[columnsInImage rowsInImage] are arrays of the indices in the image--at the command line try
{X,Y]=meshgrid(1:3,1:3)
to see what a (teeny, tiny) image might be.
So, then circlePixels is just a logical array that is T for those places in [X,Y] that have a radius less than the defined radius of the circle. Ergo, they're the points in the regular grid of points that are inside the boundary of the circle.
It's a rectangular array of 0/1 values that if printed would approximate a circle by the presence of 1's centered around where the center of the circle is in the image.
Kash Costello
il 31 Ott 2018
Risposte (0)
Categorie
Scopri di più su Lighting, Transparency, and Shading in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!