How to draw a sine wave in image
9 views (last 30 days)
Show older comments
I want to draw a sine wave in image and i want to save this image without plot. Because i cant save image with plot function as i want.


1 Comment
Accepted Answer
Guillaume
on 8 Jan 2018
Simply calculate the coordinates of the pixels you want to set according to your equation. e.g:
img = zeros(200, 600); %demo image
numperiods = 8;
amplitude = 50; %pixels
offset = 100;
x = 1:0.25:size(img, 2); %pixel subsampling for better resolution
y = sin(x*2*pi/size(img, 2)*numperiods)*amplitude + offset;
img(sub2ind(size(img), round(y), round(x))) = 1;
imshow(img);
4 Comments
Guillaume
on 9 Jan 2018
- Create a new image the same size as your letter image
- Draw the wave onto that new image
- imdilate that new image
- use that image as a mask to set pixels to 1 in your letter image
That last step is:
letterimage(logical(waveimage)) = 1; %assuming an image of type double
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!