We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Creating a face out of text/type
Pages: 1 2 
Creating a face out of text/type ? (Read 15267 times)
Creating a face out of text/type ?
May 25th, 2005, 2:39am
 
Hi there,
 
Im very new to all of this so please bear with me if I ask silly questions!  
 
What I am wanting to do is to take a photo of a human face and use processing to create a copy of the photo but using type & letterforms etc. to make the image. So, a face made out of type & letters, like in this poster here:  http://diwww.epfl.ch/w3lsp/research/microstructureimaging/siggraph-face.gif
 
How would I go about doing this?
 
Thanks,
Kate
Re: Creating a face out of text/type ?
Reply #1 - May 25th, 2005, 9:56am
 
well.. just some pointer off the top of my head..
you should read every Xth pixel, determine it's black/white-value, and scale a font accordingly..

i'm guessing this could be tricky to get looking good..
but still, the best of luck

-seltar
Re: Creating a face out of text/type ?
Reply #2 - May 27th, 2005, 12:51pm
 
i actually made it.. took me less than half an hour, so it wasn't as hard as i thought.. :)
This is for webcam though.. but you can load an image into i.e. img, and change myCapture.pixels to img.pixels or something.
ask and thou shalt recieve help.

http://wliia.org/projects/video/textCam/textimg-322984.jpg
http://wliia.org/projects/video/textCam/textimg-3647328.jpg
http://wliia.org/projects/video/textCam/bwTextCam.pde

this is basicly what you need: color [] src are the same as img.pixels

Code:

usage:
drawLetters(myCapture.pixels,5);
drawLetters(checkInput(myCapture.pixels).pixels,5); // for dramatic effect

----

void drawLetters(color [] src, int spacing)
{
for(int j = 0; j < vheight; j+=spacing)
{
for(int i = 0; i < vwidth; i+=spacing)
{
fill(0);
//fill(src[j*vwidth+i]); // uncomment this if you want colored fonts
textFont(dFont,determineFontSize(getAreaBrightness(src,i,j,spacing)));
text(BaseTable[(int)random(0,BaseTable.length)],i*2,j*2); // let it pick randomly.. lots a bit messy, but it works.
}
}
}

int determineFontSize(int b)
{
if(b < 30)
return fSz+25;
if(b < 60)
return fSz+23;
if(b < 90)
return fSz+21;
if(b < 120)
return fSz+19;
if(b < 150)
return fSz+17;
if(b < 180)
return fSz+15;
if(b < 210)
return fSz+13;
if(b < 240)
return fSz+11;
if(b < 255)
return fSz+10;
return fSz;
}

int getAreaBrightness(color [] src, int x, int y, int sz)
{
int bval = 0, count = 1;
int xw = x+(sz*(vwidth/vheight)), yh = y+sz;

for(int i = x; i < xw; i++)
{
for(int j = y; j < yh; j++)
{

bval += brightness(src[j*vwidth+i]);
count++;
}
}
return (int)(bval/count);
}

PGraphics3 checkInput(color [] video){
PGraphics3 tmp = new PGraphics3(vwidth,vheight,null);
int black = color(0,0,0); // Declare some constants for colors.
int white = color(255,255,255);
int threshold = 127;

int pix_val; // Declare variables to store a pixel's color.
float pix_bri;

// Split the image into dark and light areas:
for (int i=0; i<video.length; i++){ // For each pixel in the video frame,
pix_val = video[i]; // fetch the current color in that location,
pix_bri = brightness (pix_val); // and compute the brightness of that pixel.

if (pix_bri > threshold){ // Now "binarize" the video into black-and-white,
tmp.pixels[i] = white; // depending on whether each pixel is brighter
} else { // or darker than a threshold value.
tmp.pixels[i] = black;
}
}
return tmp;
}


hope this helps you out

sincerly
seltar
Re: Creating a face out of text/type ?
Reply #3 - May 27th, 2005, 1:48pm
 
or do it the old-school way:

lightest ---------------------------------------> darkest
.'`,^:";~-_+<>i!lI?/\|()1{}[]rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@
Re: Creating a face out of text/type ?
Reply #4 - May 27th, 2005, 4:07pm
 
like so?:
http://wliia.org/projects/video/textCam/oldschool.jpg
http://wliia.org/projects/video/textCam/oldschool-inv.jpg

not many changes, but here's the source
http://wliia.org/projects/video/textCam/oldschoolTextCam.pde


-seltar
Re: Creating a face out of text/type ?
Reply #5 - May 28th, 2005, 4:10am
 
Awsome! Thanks so much for that... I cant wait to get home and have an experiment with everything...

Quick question: The image I upload, should it just be a halftone image?

Thanks,
Kate
Re: Creating a face out of text/type ?
Reply #6 - May 28th, 2005, 5:46am
 
I caught a glance of this and decided to spend my evening playing with it.

http://mkv25.net/applets/bendyTextPhoto/

I rewrote your code Seltar initially so I could load in my own iamges, but then I ran into other difficulties, I wasn't sure how some bits operated.

Anyhow, after overcoming those problems, I had a go at bending the mapping grid and rotating the letters by a small amount. I did this by applying a noise map and and shifting the points random away from where they should be. The turning angle is calculated from the previous point on that row.

I think altering the font size may have been a better choice then using different density letters. Its more interesting when words form =)

Kate, I was using colour images in my version.
Re: Creating a face out of text/type ?
Reply #7 - May 28th, 2005, 7:28am
 
Cool man Smiley your was prettier than mine, but maybe you're just using a better font than i was Wink
still .. really cool to see other peoples versions of the same projects Smiley

-seltar
Re: Creating a face out of text/type ?
Reply #8 - May 28th, 2005, 8:31pm
 
a very quick hack using markavians code:
http://hippocamp.panicnow.net/media/ascii_cam/ascii_cam.txt

adjusted to work with a webcam, performs very slowly and isn't tweaked too well.

i'll try and implement some simpler code and see if the performance improves. unless one of you geniuses wants to do it... Smiley
Re: Creating a face out of text/type ?
Reply #9 - May 29th, 2005, 5:53am
 
BSR, I rewrote the code slightly so that it generates the offsets and preangles at the start and stores them in an array, that should speed things up for your webcam version.

I also changed it so that it would use different weight fonts and different sizes for different densities and use a set array of letters instead.

http://mkv25.net/applets/bendyTextPhoto_2/
http://mkv25.net/applets/bendyTextPhoto_2/letterPhoto.png
Re: Creating a face out of text/type ?
Reply #10 - May 30th, 2005, 2:00pm
 
I tried your code, and after a few modifications it worked. My question is, why are there differences ? Why did you use character instead of charAt, why did u miss to declare some vars, etc ? I know u did them for a reason, because I'm sure it woked for you. I'm using P0090.
Re: Creating a face out of text/type ?
Reply #11 - May 30th, 2005, 6:49pm
 
same here.. didn't work, copypasting it.. had to fix all the errors, and still i'm not sure it worked like you intended.. but i guess you've uploaded an older version of your code or something .. still.. good job:)

the problem now is speed.. how could we speed it up..
i'm guessing writing all those fonts to a pgraphics3 offscreen as an image, then outputting just the image, would increase it a little bit, is my guess..
Re: Creating a face out of text/type ?
Reply #12 - May 31st, 2005, 1:56am
 
seltar wrote on May 30th, 2005, 6:49pm:
...i guess you've uploaded an older version of your code or something .. still.. good job:)

the problem now is speed.. how could we speed it up..
i'm guessing writing all those fonts to a pgraphics3 offscreen as an image, then outputting just the image, would increase it a little bit, is my guess..


Absolutely right, I uploaded an older version of my code. I've updated it now. I did use charAt() in the end, and put in variables for int globalLetterCount and String characters.

Speeding it up, toughy, how much time does it take to draw all those characters You could increase the smaple spacing, the size of the the input image (crop it down to only the central bit). I don't know how you'd make the code any more optimal.

I'm more interested in print versions. I added a 'scale' variable so that you can easily doule/treble the size of the output and save it so it can be printed out. I printed a few out they look pretty good from a distance.
Re: Creating a face out of text/type ?
Reply #13 - May 31st, 2005, 11:58pm
 
In my latest version, I've produced a rendering system that breaks down the input image into smaller segments that can be rendered at large scales, and then stiched back together in a paint editing program (I used paint shop pro).

The image I used in the example was a Harry Potter poster of Sirius. The backing text is an extract from the third book, The Prisoner of Azkaban in the scene where they discover Sirius is an animagus and confront him.

http://mkv25.net/applets/textPhotoPrintRender/

I scaled down the images by 50% from the originals, I printed the originals out on A4 and they look pretty good on my wall.

I put in an option to disable the bendy grid because it gets quite hard to follow the passage of text with the distortion introduced and I thought that was an important part. Saying that, the bendy version looks much more intriguing from a distance when put side-by-side with the grid version.

I also tried mixing the original image with the text version (using Paint Shop Pro and layers), which produces some very nice results but ultimately renders the text unreadable in most cases.
Re: Creating a face out of text/type ?
Reply #14 - Jun 1st, 2005, 12:48am
 
Is it possible to configure the bendy grid from the pixel values? It'd look much better than the random one, IMHO, but not necessarily easy...
Pages: 1 2