필터 지우기
필터 지우기

I NEED TO MAKE A HEART in a CANVAS

조회 수: 24 (최근 30일)
tzela yaish
tzela yaish 2018년 10월 17일
댓글: Image Analyst 2018년 10월 17일
i have a code in MATLAB,
i created a canvas with 3 pages 1000 rows and 1000 columns with a circle in the middle (the size doesnt matter) such:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
canvas = ones (1000,1000,3,'uint8'); canvas(:,:,1) = 255; canvas(:,:,2) = 0; canvas(:,:,3) = 0;
rad = 260; rows = 500; col = 500; for n = -rad:rad d = round(sqrt(rad^2 - n^2)); canvas (rows-d:rows+d,col+n,:) = 255; end
imshow (canvas)
%%%%%%%%%%%%%%%
I NEED to generate a HEART IN THE MIDDLE INSTEAD OF THE CIRCLE... can someone help me with that please ???

답변 (2개)

Image Analyst
Image Analyst 2018년 10월 17일
Try this:
% Plots 2 heart-shaped curves.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
t = linspace(-pi,pi, 350);
X = t .* sin(pi * .872*sin(t)./t);
Y = -abs(t) .* cos(pi * sin(t)./t);
plot(X,Y);
fill(X, Y, 'r');
axis square;
set(gcf, 'Position', get(0,'Screensize'));
title('Happy Valentines Day', 'FontSize', 28);
% axis off; % Uncomment to turn off tick labels along the bottom and left axes and remove the box.
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
%------------------------------------------------------------------------------
% Another method.
% https://blogs.mathworks.com/cleve/2018/02/14/happy-valentines-day/
figure;
ezplot('(x^2+y^2-1)^3 = x^2*y^3', ...
[-1.5,1.5,-1.2,1.5])
colormap([.5 .2 .2])
  댓글 수: 2
Image Analyst
Image Analyst 2018년 10월 17일
tzela's "Answer" moved here since it's a comment to me rather than an answer to the original question:
thanx, but i need a code that will implement it into CANVAS .... IN THE CENTER. thats where im having an issue
Image Analyst
Image Analyst 2018년 10월 17일
So use scale x and y to the desired size and then use poly2mask() to turn it into an image
scale = 100; % Whatever
canvass = poly2mask(scale*x, scale*y, rows, col);
adjust scale as needed.

댓글을 달려면 로그인하십시오.


tzela yaish
tzela yaish 2018년 10월 17일
thanx, but i need a code that will implement it into CANVAS .... IN THE CENTER. thats where im having an issue

카테고리

Help CenterFile Exchange에서 Valentines Day에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by