How to make a photo look as a drawing (the silly way)
I’ve been asked to explain how I converted the photo of our friend singing and playing her guitar into something that barely resembles a handmade drawing. This isn’t, of course, anything original and a lot of image editors have a function to do it, but I prefer it to follow the longest path because I’m a masochist.
To do this I used MATLAB with Image Processing Toolbox functions. There’s also a free software counterpart (GNU Octave) that has a lot of image processing functions in the Octave Forge project, but I thought I would need grayscale dilation and erotion, thus I decided to use the propietary MATLAB (hey! it won’t happen again! I promise). This probably will run well in Octave though, if we consider the subtle differences in imread behaviour (it doesn’t return a MxNx3 matrix, but 3 matrices, one for each color plane instead), and handle the fact that imresize function is missing (perhaps interp2 could work as a replacement for this task).
First of all you can see the original image (resized to a smaller size) here:
I’ll focus on the amplifier and the mixing desk which are on the right so I can include the images without having to resize them:
The first step was to open the original image and convert it to grayscale:
%% Read original image
i=imread('campaneta.jpg');
%% Convert it to grayscale
a=rgb2gray(i);
%% Resize it to a more usable format b=imresize(a,.5,'bicubic');
%% Adjust contrast d=imadjust(b);
Then I used four different methods to obtain the edges of the image (Canny, Sobel, Roberts and zero crossing detection):
%% Get edges using 4 different methods bw1=edge(d,'canny'); bw2=edge(d,'sobel'); bw3=edge(d,'roberts'); bw4=edge(d,'zerocross');
You can see the results of these operations here:
![]() Canny |
![]() Sobel |
![]() Roberts |
![]() Zero crossing |
%% We sum all edges and then
%% normalize it and negate it
bwr=1-(double(bw1)+double(bw2)+
double(bw3)+double(bw4))/4;
%% resizes image to 300 pixel-width, its final size prefinal=imresize(bwr,300/744,'bicubic');
%% auto-stretches image contrast final=imadjust(prefinal);
This is how the whole image looks like.
There’s only one thing left: drawing a border to the image, because leaving all those lines open doesn’t look very good. After that imwrite saves the image to disk.
%% 1 pixel wide black border s=size(final); final(1,:)=0; final(s(1),:)=0; final(:,1)=0; final(:,s(2))=0; %% write result to disk imwrite(final, 'neverland_fairy.png');
The result doesn’t look bad (if you take into account that this is automatable and doesn’t need any hand-editing), don’t you agree?
Perhaps it would be nice to try to stick with only one edge detector method and play with its threshold. If you want to give it a try, please tell me how does that work.
Hey… why don’t you do it the easy way?
Errr… yes… Just do this (I’ve translated the menu labels from Catalan to English so they could be slightly different; but you are smart enough to find them):
- Open the file in the Gimp.
- Filters/Edge detection/Gaussian
- Radius 1: 10; Radius 2: 1, Normalize and Invert.
- Image/Mode/Grayscale
- Image/Scale
- Width: 300px, Cubic interpolation.
- Layers/Colors/Levels
- Set central level to 0.13
Well this is what you’ll get. Looks nicer, doesn’t it? This is just because the threshold of the edge detector is set much lower. Using graphical programs lets you choose the best-looking settings very quickly. But the first way was much more fun!





March 3rd, 2005 at 08:21
també es pot fer amb photoshop, però suposo que com tu no vols saber res de microsoft……
ostres, quina gràcia de fer de model jijijijijijiji
March 3rd, 2005 at 12:31
photoshop-microsoft como que no, és photoshop-apple. apa! ja et pots ficar un altre cop amb els maqueros…
March 3rd, 2005 at 12:51
Bah! No em compraré un programa que val el que val quan tinc el Gimp que és lliure i és més que suficient per les meves habilitats.
I si em falta alguna cosa programo un plugin.
March 3rd, 2005 at 13:00
Ei! A mi els maqueros ja m’agraden! Per això tenia un iBook. Molt millor el MacOs X que Windows! I molt maco el ferro d’Apple.
El que passa és que, mentre uns només valoren el preu i les funcionalitats (Windowseros) als altres de vegades els perd l’estètica i tant se’ls en fot que les coses siguin pràctiques mentre siguin boniques (animacions llarguíssimes, etc… tots sabem de què parlem).
És divertit.
Als Linuxeros ens perd la consola. Triguem 3 vegades més en fer una cosa que un maquero fa en 3 clics per saber com funciona per sota i perquè la pantalla negra és més geek.
March 3rd, 2005 at 13:22
Ostres! Avui estic xerraire!
Només dir que els que utilitzem GNOME ja tenim un escriptori que estèticament està força currat i, a més, molt còmode. Una de les grans preocupacions del projecte és fer aplicacions senzilles i que tot vagi amb el menor nombre de clics possibles.
A més està molt inspirat en els macs….
I en català…
Proveu-lo si podeu…