# EXPERIMENTING WITH LENNA

Posted March 15, 2012 at 13:21 in Graphics, Illustrator, Scriptographer - 1 comment

I have been experimenting with different kinds of raster effects lately. Not really breaking any new grounds here but it is fun to try to come up with new stuff and just to play around for a while. The hardest part is to find a suitable image to apply these effects on and most of the time I just throw some random image just lying in the downloads folder. Then it hit me, I’ve read about this picture that is somewhat associated with image processing experiments (I believe it was on this site about dithering). Not because it’s an optimal image for such operations, on the contrary actually, but because it was what was laying around in time of need. So, without further ado, meet Lenna.

Now, when I had an image to work with I quickly wrote a function that divide the image into a number of rectangles that then takes on the average color of its underlying area – I’ll be refering to this rectangle as the color sampling area. This function then calls other small functions that applies all the different rasters I could think of. Here is a run-down of the effects.

STANDARD MOSAIC RASTER
This is a pretty straight forward mosaic raster effect but I managed to optimize the process as it’s usually made by drawing a bunch of rectangles that acts like a pixel. This will put considerable strain to Illustrator because, as we all know, a rectangle has four corners that it has to keep track of. Therefore the amount of anchor points will be four times that of the number of objects.

The image above contains 16,384 rectangle objects which would, under normal circumstances, equal to 65,536 anchor points. But, instead of making rectangles I’m drawing the objects as vertical lines with strokes applied to the lines the size of the sample area. This way I get by with only half of the anchor points; 32,768. The two images below show the difference.

351 rectangles = 1,404 anchor points

351 paths = 702 anchor points

Another advantage, I think, is that I can choose to modify the width of the strokes. Below is an image that has the exact same properties as the previous only the stroke width is half of the color sampled area. This results in a kind of white, vertical interference pattern.

RGB PIXEL RASTER
This is supposed to imitate the pixels of old cathode ray TVs. Nothing fancy but just something that I had to try out.

It made for a somewhat nice effect but not very special. Not until I started to play around and rotating each pixel by 90 degrees increments yielding a very prominent pattern. While I was kinda surprised at the outcome it seems it’s too limited to be of any use.

In an effort to reduce the patterning a bit I let the “rgb-pixels” rotate randomly, again in 90 degrees increments.

This could have been it had I not kept on manipulating the outcome. I isolated the different color channels in Photoshop but neither the red nor the blue channel where very interesting. The green one, though, was way cooler.

Clearly this cross-hatch pattern has a lot more to offer than the previous two. So much so, in fact, that I imported the result to Photoshop where I ramped up the contrast and had the green color desaturated.

I feel the end-result is interesting enough to warrant its own script. Got to get to it.

DASHED RGB PIXEL RASTER
When thinking of CRT pixels I came up with yet another way. What if the red, green and blue intensity of each pixel was always at its maximum value and instead just activate parts of it. I don’t really know how to explain it, but I’ll give it a try. Below, anyway, is the final outcome and at first, it didn’t come out quite as I expected. It looks kinda inverted, but…

…the colors are still preserved and when adding a black background it turns the image into this.

Each of the sampled areas are divided into 3 x 8 “cells”. The higher value of each color channel the more of the “cells” are going to be filled in.

For instance, above is the average color of the complete Lenna image. The color components are, [177, 99, 106], so dividing by 32 and rounding to its nearest integer on each channel, gives [6, 3, 3]. So, for the red channel, 6 out of 8 “cells” are filled. Green channel, 3 out of 8 are filled and for the blue – yep you guessed it – 3 out of 8. These numbers are then randomly distributed which means that two colors with exactly the same channel values might not be diplayed in the same way.
Unfortunately, Illustrator can only make dashed strokes with a maximum of three dashes and three gaps. Therefore, a line in the form of;

`dashArray = [dash, gap, dash, gap, dash, gap, dash]`

will not display correctly as Illustrator simply ignores the input from the last dash and onwards. Instead – as a workaround – the last dash will have to be added to the first. So, let’s say a color channel array looks like this;

`dashArray = [1, 0, 1, 0, 1, 0, 2]`

In order to be a valid dash array it would have to be re-arranged like this;

`dashArray = [3, 0, 1, 0, 1, 0]`

I don’t know if I’m making any sense trying to explain how it works but the end-result is quite nice, I think.

RGB + CMYK PIXEL RASTER
Now this is starting to get a little too far fetched. I split each sample area into an 8 “cell” pixel, converted all color channels into binary and performed almost like a bitwise OR operation.

The same average image color as before. The color channels – in binary – reads like:

```red   = 10110100
green = 01100011
blue  = 01101001```

Then, taking one number from each channel in sequential order yields RGB values as such:

```Red   = rgb(1, 0, 0)
Cyan  = rgb(0, 1, 1)
White = rgb(1, 1, 1)
Red   = rgb(1, 0, 0)
Blue  = rgb(0, 0, 1)
Red   = rgb(1, 0, 0)
Green = rgb(0, 1, 0)```

and finally

`Cyan  = rgb(0, 1, 1)`

I know, I’m not making any sense here and I think the outcome is not very comprehensive either, or nice for that matter. Maybe it could used for glitch art or something. Anyway, one can BARELY work out some details in the image so I guess this one is the least useful of the bunch.

### One Response to “EXPERIMENTING WITH LENNA”

1. Andrew
October 19th, 2016 at 3:04

Hey Monovektor!
I was looking at your post about Experimenting with Lenna/ working with algorithms to create raster effects and it gave me an idea. I’m doing an exhibition project for my University and wanted to build a lego mosaic out of the DASHED RGB PIXEL RASTER version you did of Lenna to simulate how the eye perceives color on a computer screen, but on a smaller scale with a different image. I’m not entirely familiar with the techniques you used and wondered if you might share how to create such an image? Thank you and best reguards!!
-Andrew