I need some image programming advice

I am trying to build a high resolution image that consist of vertical lines from other images.

To be exact: I want to build an image that is 3888×2592 pixels. I want to build it using 3888 vertical lines that are 2592 pixels high. I have a folder with 3888 high resolution images and the new image should be build by extracting vertical line number one from the first picture, vertical line number two from the second picture, vertical line number three from the third picture and so on.

Here is a very simple illustration:
Click illustration to enlarge.

It would be possible to do this manually in photoshop. Open one image, cut the first column of pixels, paste in a new image and repeat 3888 times… But this is something that would be much easier by automation. Pseudo code:

– Create new image, 3888×2592

For n = 1 to 3888
– Open image number n
– Copy column number n (1×2592 pixels)
– Paste at column number n in new image
Next n

…the problem is that I have no idea what tool to use. Could this be programmed using automator and apple script? Using automation in photoshop? Or do I need to learn xcode and do it the hard way?

Preferably a solution that could be done on a Mac.

Any advice is appreciated!

I need some image programming advice

28 thoughts on “I need some image programming advice

  1. Kristian J. says:

    Dette kan være et tilfelle av at jeg har en hammer og at det får alt til å se ut som en spiker, men det burde være nokså enkelt å få til dette med GD i PHP.

    Se http://php.net/manual/en/function.imagecopy.php for et utgangspunkt – bare pass på å kvitt deg med bildene i minnet med imagedestroy() etterhvert som du laster inn nye, ellers går du nok tom for minne.

  2. Diderik From says:

    This could probably be easily done in FSL (freely available for linux and mac, at http://www.fmrib.ox.ac.uk/fsl/), using the command line tools fslroi and fslmerge, and a simple bash script. I would rename the source images according to the number of the line you want (starting at 0, again with a simple bash script). Then make a list of your files, without the extension. Do something like this in bash, ‘while read LINE ; do fslroi ${LINE}.jpg ${LINE}_extracted.jpg ${LINE} 1 0 2591 0 0 ; done < list'. Then 'fslmerge -x merged_in_x_direction.jpg files…'

  3. Aleksander Krzywinski says:

    I would have used Java. Most likely because that is the programming language I have the most experience with, but also because the Java2D API is fairly easy and Java runs cross platform.

  4. This is done easily with ImageMagick and a little bash scripting:


    tmpdir=tmp
    if [ -d "$tmpdir" ]; then
    rm -rf $tmpdir
    fi
    mkdir $tmpdir
    height=2592
    width=10
    n=0
    for f in *.jpg
    do
    offset=$(($n*$width))
    c="$(printf "%05d" $n)"
    echo "Creating slice $tmpdir/$c.png"
    convert -crop ${width}x${height}+${offset}+0 $f $tmpdir/$c.png
    n=$(($n+1))
    done
    count="$(ls -1 $tmpdir | wc -l)"
    echo "Joining $count slices into out.png"
    montage $tmpdir/*.png -mode concatenate -tile ${count}x out.png

    view raw

    eirikmagick.sh

    hosted with ❤ by GitHub

    After you have installed imagemagick and curl, open a terminal window and cd to your image folder. Then run:

    curl https://gist.github.com/raw/739744/f262f94a1a79f0c89bd4e2c56f1f40922cd81567/eirikmagick.sh | sh

    You’ll find your new image in out.png in the same folder.

    Feel free to tweak the script online by forking my gist. Follow the “raw” link to get the URL of your updated script.

  5. Eirik,

    Assuming you’ve got ImageMagick correctly installed on your Mac, this would be one way to do it, using perl.

    This example assumes 16 gif files named 01.gif trough 15.gif, and every one 16×16 pixels big. The script crops out one pixel wide row from each gif and creates a new gif file for each. In the end the script merges all of them into one single gif file.

    I’m not sure whether this would work with images sized like yours — I think you may run into command line limitations on the final command/line here — but hopefully this’ll give you a starting point.

    #!/usr/bin/perl

    use strict;

    my ($cropwidth, $cropheight) = (1, 16);
    my $i = 1; # Assumes that first file is named 01.extension
    my $filetype = “.gif”; # Change to whatever extension you use
    my $maxfiles = 15;
    my $flattenedfile = “flattened” . $filetype;

    while ($i <= $maxfiles) {
    # Change %02d to %03d if three digit number, %04d if four digits etc.
    my $filename = sprintf("%02d", $i) . $filetype;
    my $offset = $i – 1;
    my $convertedfile = "converted-" . $filename;
    `convert $filename -crop ${cropwidth}x${cropheight}+$offset $convertedfile`;
    $i++;
    }

    `convert converted-*$filetype -background white -mosaic $flattenedfile`;

  6. Jesper says:

    You should be able to make a comp in Quartz Composer (part of OSX dev-kit). I have no time to do this right now, but the nodes in Quartz are quite self-explaining.

  7. Onno ter Wisscha says:

    Funny to see that no one seems to wonder what the heck you try to create.
    (and just hand you solutions which is a good thing of course)
    I just became very interested in what is behind your question.
    The only useful result would be from a series of pictures that are fairly similar.
    Like a stop-motion sequence or a time-lapse series.
    Or a self-portrait shot every day for the last ten years.
    Do you want to capture time and/or motion in your result?
    Can you share some of your thoughts or do we have to wait for the result?

  8. Hehe. We’re talking solution oriented and pretty fantastic people here. 🙂

    Aslak’s solution is the one I’m playing around with now. And you are right. This year’s time lapse project is my old Canon 400D that have been mounted in my window for nearly a year now. Snapping an image every half hour…

    So, I have a repository of images shot at EXACTLY the same place now. Around 15 000 of them actually.

    And now I have started to play with the content. Making time lapse trials and this little project: making an image that consist of 3888 other images snapped all through one year.

    This is the quick test Aslak did on around 300 images I sent him:
    http://yfrog.com/h44kpdj

    I’m working on the 3888-lines-version now. I promise I’ll post more on this later!

  9. Onno ter Wisscha says:

    Thank you for keeping us up to date.
    Looks very promising.
    It will be hard though to match the impact and awesomeness of your time lapse video.
    Unless….
    you make a video of shifting sliced up pictures…
    See the seasons slide from left to right.
    Just a thought.
    And a hell of a job 🙂

  10. that’s some problem you got there.. but I’m not progamming guru but I would suggest an open source image editor w/ an slicer that can slice your image 1 pixel column per image, then just reprogram it to your algorithm to create a new image. Probably one that has a batch process feature.

  11. I was looking at this and thinking about how the somewhat abrupt transitions and vertical lines could be ameliorated. The easiest way to do it would be to slice into three pixel panels, glue them together (ending up with an image 3x the final width), and then run through a lossy 2d convolution like [0.2, 0, 0.6, 0, 0.2] on the center column of each panel. That way each column would end up being 20% of yesterday, 60% of today, and 20% of tomorrow.

  12. I would love to combine Onno ter Wisscha’s and Peter da Silva’s suggestions. It would make such a beautiful video!
    I would program this using ImageMagick and mencoder.

    It would be great if you were able to upload these images somewhere, maybe as a torrent?

Leave a comment