free hand drawing on photo matlab

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.

Risposte (3)

Image Analyst
Image Analyst il 23 Mag 2016

1 voto

You might want to use Photoshop or Gimp.

3 Commenti

win tun
win tun il 23 Mag 2016
Thanks for advice @Image Analyst. I would like to make this task (drawing on photos) as part of the codes. (i.e. When I run the code, the photo appears and let me draw on it. Then after finishing drawing, I want to code continue running for next steps. Do you think if it is possible. Thanks for advice again.
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
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.

Accedi per commentare.

KSSV
KSSV il 23 Mag 2016

0 voti

3 Commenti

win tun
win tun il 23 Mag 2016
Hi @Dr.Siva. Thanks for your kind advice. I have tried the code that you've mentioned. It did allow me to draw on the screen, but not on the photo. I am not sure how I can open photo for drawing. Please guide me if you have any suggestions. Tks ahead.
KSSV
KSSV il 24 Mag 2016
Modificato: KSSV il 24 Mag 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 il 24 Mag 2016
yes, now I got it. Thanks @ Dr Siva !

Accedi per commentare.

Richiesto:

il 23 Mag 2016

Commentato:

il 24 Mag 2016

Community Treasure Hunt

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

Start Hunting!

Translated by