How to draw a sine wave in image

9 views (last 30 days)
umut
umut on 8 Jan 2018
Commented: Guillaume on 9 Jan 2018
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
Stephen23
Stephen23 on 8 Jan 2018
Edited: Stephen23 on 8 Jan 2018
@umut: an image is just an array of numbers. There is nothing stopping you from changing some of an array's values, following any curve you wish. You do not need to plot anything to do this.

Sign in to comment.

Accepted Answer

Guillaume
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
umut
umut on 8 Jan 2018
sorry sir i asked so many question but this function thickens both letters and waves. I just want to thicken wave.
Guillaume
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

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!