Creating a star shape using the imshow() function.
显示 更早的评论
The shape should look like a star
⭐⭐
and should use MATLAB and the imshow() function.
回答(2 个)
Image Analyst
2016-12-10
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
stepSize = 360 / 5;
angles1 = 0 : stepSize : 360;
angles2 = stepSize/2 : stepSize : 360 + stepSize/2;
r1 = 150;
r2 = 300;
x1 = r1 * cosd(angles1);
y1 = r1 * sind(angles1);
x2 = r2 * cosd(angles2);
y2 = r2 * sind(angles2);
subplot(2,2,1);
plot(x1, y1, 'LineWidth', 2);
hold on;
plot(x2, y2, 'LineWidth', 2);
grid on;
x3 = reshape([x1;x2], 1, []);
y3 = reshape([y1;y2], 1, []);
% Shift center to 500, 500
x3 = x3 + 500;
y3 = y3 + 500;
subplot(2,2,2);
plot(x3, y3, 'LineWidth', 2);
% Make 900x900 image from the coordinates.
subplot(2,2,3);
maskImage = poly2mask(x3, y3, 900, 900);
imshow(maskImage);
axis on;

2 个评论
ammar khider
2016-12-11
Image Analyst
2016-12-11
Then you do not have the Image Processing Toolbox. Use the ver command to check. You'll have to use some other way to turn the vertices into an image, which you need to do because it says you must use imshow().
Image Analyst
2016-12-11
0 个投票
Fancier demo attached.

类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!