?

Log in

No account? Create an account
Random Dot Stereograms - Sarah's Blog [entries|archive|friends|userinfo]
Sarah

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Random Dot Stereograms [Mar. 8th, 2007|02:32 pm]
Sarah
I've made a RDS creator on our server, using a bit of C#. Below is what it creates so far. I can throw variable sized images at it, and it'll make a nice RDS, but I have to change the code to change the picture. =(
I'm hoping to be able to add a nice page for people to upload an image, or provide a URL to one so they can make their own, just as soon as I work out what commands are needed. o.O

It -can- use a covering image... but I'll be adding that on last.
It also features my own line of code to create the RDS... the fastest I've come up with so far. (That's right... one line! These things are easy if you simplify the theory.)





Here's the original...



And here's the source for it so far... the RDC creation algorithm is emphasized.

<% @Page Language="C#" Debug="true" %>
<% @Import Namespace="System.Drawing" %>
<% @Import Namespace="System.Drawing.Imaging" %>
<script language="c#" runat="server">


void RDS(Bitmap bitmap,int stripWidth)
    {
    Random rnd = new Random();

    int randomDotColour,width,height;
    float scaling;

    width=bitmap.Width;
    height=bitmap.Height;

    scaling=((float)stripWidth/(float)5)/(float)255; // This makes sure full white (high points are white and have a value of 255) are always 1/5th the width of the image strip.

//Draw the random strip
    for(int y=0;y<height;y++)
        for(int x=0;x<stripWidth;x++)
            {
            randomDotColour=rnd.Next(0,2)*255; // Random number,either 0 or 255
            bitmap.SetPixel(x,y,Color.FromArgb(255,randomDotColour,randomDotColour,randomDotColour));
            }

//Create the RDS
    for(int x=stripWidth;x<width;x++)
        for(int y=0;y<height;y++)
            bitmap.SetPixel(x,y,bitmap.GetPixel(x-stripWidth+(int)(scaling*bitmap.GetPixel(x,y).R),y));


//Send the picture back to the browser
    Response.ContentType = "image/gif";
    bitmap.Save(Response.OutputStream, ImageFormat.Gif);
    bitmap.Dispose();
    }


//Start here :p
void Page_Load(Object senter, EventArgs e)
    {
    Bitmap bitmap = new Bitmap("f:/Inetpub/wwwroot/RDCLive/rds/shark.png"); // http://rdc.untamed.co.uk/rds/shark.png
    RDS(bitmap,90);
    }
</script>
linkReply

Comments:
[User Picture]From: nicollegurrl
2007-03-08 05:15 pm (UTC)
I love these 3d pictures,I have a book somewhere from when they
were very popular in the 90s :-)
(Reply) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 12:24 am (UTC)
Yes! I remember people were buying hard-back books with them in!
(Reply) (Parent) (Thread)
[User Picture]From: becky44
2007-03-08 08:01 pm (UTC)
I like it!!!

It's given me some slightly strange images... I thought at one point I was seeing multiple sharks - and then I'm sure I saw some artifacts along the side of the shark! But my eyesights daft anyway!
(Reply) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 12:24 am (UTC)
Wibble?
(Reply) (Parent) (Thread)
[User Picture]From: acidgirltogo
2007-03-08 08:16 pm (UTC)
"You dumb bastard, it's not a scooner, it's a sailboat!"
(Reply) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 12:24 am (UTC)
I think you'll find it's a duck with horns.
(Reply) (Parent) (Thread)
[User Picture]From: porcelaingirl
2007-03-08 10:22 pm (UTC)
I added your other journal; just letting you know. ^_^

*hugs*
Catie
(Reply) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 12:25 am (UTC)
Heh, brill! I was wondering if you would.
(Reply) (Parent) (Thread)
[User Picture]From: solar_angel
2007-03-08 10:31 pm (UTC)
Not bad at all. I haven't written one of those since I was 10.
(Reply) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 12:27 am (UTC)
I remember getting a pen out and trying to work out how the ones in "The People" newspaper were created. I didn't have the internet back then, so I don't think I ever got a properly working one. I remember that sometime after that I got a working program on an Acorn Arch in highschool, but I can't remember if I'd worked it out, or read how it was done. Fascinating things though, dispite their age.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: sarahs_muse
2007-03-11 12:29 am (UTC)
Wow, scary trig stuff.

I lack the brain power to look at something like that and see what's wrong, perhaps lots of coffee and hands-on experiments would work. =)

That was an interesting program for high school, was it from a class you took, or was it your own private work?
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: sarahs_muse
2007-03-11 11:01 am (UTC)
Heh!

Using your huge brain to comprehend a big trigonometric problem doesn't always get the best possible answer.

Take me for example... Once I learned that : pixel brightness = offset
I then just threw all the maths shit out the window and never look back (*after* the depth image was made ^-^ ). That's why my generator programs about ... 1 line long. ^-^

Original magic eye pictures start with the original strip on the left, then get offset through the whole image, so by the time the strips used on the right, it's pritty mangled.
If you use a recognisable image in the strip (like M & M's) instead of random dots, the effects worse.

While I was looking at the Magic Eye images, I noticed an interesting technique they used to reduce this... they started the magic eye offsetting in the middle, so the middle strip had NO offset in it, and the strips to the left and to the right were offset left and right instead.
My reconstruction of this always left a strip in the middle that was flat, I never did work out what was wrong.

Your icons cool. =)
(Reply) (Parent) (Thread)
[User Picture]From: sarahs_muse
2007-03-11 11:03 am (UTC)
Are there any freeware pascal JIT compilers I could use to run them?
(Reply) (Parent) (Thread)