free hand drawing on photo matlab

4 views (last 30 days)
win tun
win tun on 23 May 2016
Commented: mee mee on 24 May 2016
How can I draw freehand on photo opened by imshow
%a=imread('tree.jpg)
imshow(a);
%then how can i draw on tree photos as i wish??
As mentioned above, I would like to open a gray scale photos (left) and then want to draw on it by freehand (as shown in right). What command shall I use to allow me to draw on photo? Can anyone suggest me? Thanks.

Answers (3)

Image Analyst
Image Analyst on 23 May 2016
You might want to use Photoshop or Gimp.
  3 Comments
win tun
win tun on 23 May 2016
Now I found a code written by someone
I = imread('peppers.png');
imshow(I);
for i=1:3
M = imfreehand(gca,'Closed',0);
end
F = false(size(M.createMask));
P0 = M.getPosition;
D = round([0; cumsum(sum(abs(diff(P0)),2))]);
P = interp1(D,P0,D(1):.5:D(end)); % ...to close the gaps
P = unique(round(P),'rows');
S = sub2ind(size(I),P(:,2),P(:,1));
F(S) = true;
figure;
imshow(F);
imwrite(F,'line.jpg')
It seems useful for me. I can draw the line on the photos and it will save the line that I draw in the fig (line.jpg). That is what I want. But the problem is that I am drawing three lines (as i=1:3), but only the last line is saved. So, how can I change the codes so it will save all lines I draw. Example photos are below (where only the right most line is saved and shown). How to do all three lines are saved and shown? Tks
Image Analyst
Image Analyst on 23 May 2016
You have to get a mask
mask = M.createMask;
Then for each color channel, set the value, like to 255:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Burn line into images
redChannel(mask) = 255;
greenChannel(mask) = 255;
blueChannel(mask) = 255;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
You can probably do it all in one line with bsxfun() but I don't know what it is.

Sign in to comment.


Image Analyst
Image Analyst on 24 May 2016

KSSV
KSSV on 23 May 2016
  3 Comments
KSSV
KSSV on 24 May 2016
Edited: KSSV on 24 May 2016
Hi Win tun I tried the above code to draw on a image, it is working fine. First open your image using 'imshow' and then call this function; it will allow you to draw free hand. Cheers
mee mee
mee mee on 24 May 2016
yes, now I got it. Thanks @ Dr Siva !

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!