フィルターのクリア

How can I convert this circle drawing code as a Function code? thank you

1 回表示 (過去 30 日間)
Maitham
Maitham 2014 年 2 月 14 日
回答済み: Maitham 2014 年 2 月 16 日
% 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');
[EDITED, Jan, code formatted]

採用された回答

Mischa Kim
Mischa Kim 2014 年 2 月 14 日
編集済み: Mischa Kim 2014 年 2 月 14 日
Maitham, check out the following:
function my_circ(imageSize, center, radius) % function definition
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = imageSize(1);
imageSizeY = imageSize(2);
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = center(1);
centerY = center(2);
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');
end % end of function
which is called (e.g., from the MATLAB command window) with
my_circ([400 600], [20 30], 50)

その他の回答 (1 件)

Maitham
Maitham 2014 年 2 月 16 日
Dear Micha Kim, Thank you for your answer and it works. Very kind regards Maitham

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by