Skip to content

Commit

Permalink
Added documentation.
Browse files Browse the repository at this point in the history
Renamed prepare to metapixel-prepare, which is now a Perl script.
Bugfixes.
  • Loading branch information
schani committed Dec 28, 1999
1 parent db2861c commit 6129962
Show file tree
Hide file tree
Showing 10 changed files with 627 additions and 25 deletions.
341 changes: 341 additions & 0 deletions COPYING

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Makefile
@@ -1,15 +1,27 @@
PREFIX = /usr/local
INSTALL = install

BINDIR = $(PREFIX)/bin

#PROFILE = -pg

LDOPTS = -L/usr/X11R6/lib $(PROFILE)
CCOPTS = -I/usr/X11R6/include -I/usr/X11R6/include/X11 -Wall -O9 $(PROFILE)
CC = gcc
#LIBFFM = -lffm

all : metapixel

metapixel : metapixel.o vector.o rwpng.o getopt.o getopt1.o
$(CC) $(LDOPTS) -o metapixel metapixel.o vector.o rwpng.o getopt.o getopt1.o -lpng $(LIBFFM) -lm -lMagick -lX11 -lz -lbz2

%.o : %.c
$(CC) $(CCOPTS) -c $<

install : metapixel
$(INSTALL) -d $(BINDIR)
$(INSTALL) metapixel $(BINDIR)
$(INSTALL) metapixel-prepare $(BINDIR)

clean :
rm -f *.o metapixel *~
95 changes: 95 additions & 0 deletions README
@@ -0,0 +1,95 @@
Metapixel 0.1
=============

Metapixel is a program for generating photomosaics. It can generate
classical photomosaics, where the source image is viewed as a matrix
of equally sized rectangles for each of which a matching image is
substitued, as well as collage-style photomosaics, in which
rectangular parts of the source image at arbitrary positions (i.e. not
aligned to a matrix) are substitued by matching images.


Installation
------------

In order to compile Metapixel, you need ImageMagick and libpng
installed at your system. To run the script for preparing constituent
images, you will additionally need Perl. Most Linux distributions
contain these software packages.

Edit the first line of Makefile if you want to install Metapixel
somewhere else than /usr/local. Then, type

make

If everything compiled fine, become root and type

make install


Preparing images
----------------

Before mosaics can be created the constituent images need to be
preprocessed. Preparing an image does two things. Firstly, it computes
various coefficients by which the image can be matched against a part
of a source image. Secondly, the image is scaled to size it will have
in the target image. Note that this size must be equal for all
constituent images and must be known in advance. The default size is
64x64 pixels.

To simplify the task of preparing images, the Perl script
'metapixel-prepare' is included in the distribution. It must be called
with two parameters: the name of directory in which the original
images are stored and the name of the directory which the scaled down
images and the table file should be stored. It also accepts parameters
specifying the size of the scaled down images. Just call it - it
prints out usage information.


Creating photomosaics
---------------------

In order to create a photomosaic for an image, it should be scaled to
an appropriate size. For classic photomosaics, the width and height of
the source image must be multiples of the widths and heights of the
small constituent images, respectively. This restriction does not
apply to collages, however.

Metapixel produces output images in the PNG format. In order to create
a classic photomosaic for the image input.jpg and write the output to
output.png with constituent images stored in the directory images, use
the following command line:

metapixel --metapixel input.jpg output.png <images/tables

To create a collage use

metapixel --collage --metapixel input.jpg output.png <images/tables

Using the -y, -i and -q parameters you can change the weights for each
of the color channels. For example, to match only luminance,
completely disregarding chrominance, use

metapixel -i0 -q0 --metapixel input.jpg output.png <images/tables

The default weight for each of the channels is 1.

Note that Metapixel uses ridiculous amounts of main memory. To create
photomosaics of size 2048x2048 your machine should at least have
64MBytes RAM.


Licence and Availability
------------------------

Metapixel is distributed under the terms of the GPL.

The source of Metapixel is available at the Metapixel homepage at

http://www.complang.tuwien.ac.at/~schani/metapixel/


---
Mark Probst
schani@complang.tuwien.ac.at
88 changes: 88 additions & 0 deletions metapixel-prepare
@@ -0,0 +1,88 @@
#!/usr/bin/perl

# metapixel-prepare --- prepare images for metapixeling.

# Copyright (C) 1999 Mark Probst

# Author: Mark Probst <schani@complang.tuwien.ac.at>
# Maintainer: Mark Probst <schani@complang.tuwien.ac.at>
# Version: 0.1

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, you can either send email to this
# program's maintainer or write to: The Free Software Foundation,
# Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.

use strict;

use Getopt::Long;
use File::Basename;
use IO::Handle;

sub usage {
print STDERR "Usage: $0 [OPTION]... <srcdir> <destdir>
Prepares all images in <srcdir> for use as small images in
photomosaics. The scaled versions and the table file are
stored in <destdir>.
--help display this help and exit
--width=WIDTH specify width of small images
--height=HEIGHT specify height of small images
";
exit(1);
}

my $width;
my $height;

if (!GetOptions("help", \&usage,
"width=i", \$width,
"height=i", \$height)) {
usage();
}

my $opts;

if ($width) {
$opts = "--width=$width";
}
if ($height) {
$opts .= " --height=$height";
}

if ($#ARGV != 1) {
usage();
}

my ($srcdir, $destdir) = @ARGV;

if (! -d $srcdir || ! -r $srcdir) {
print "$0: directory $srcdir does not exist or is unreadable\n";
exit(1);
}

if (! -d $destdir ) {
print "$0: directory $destdir does not exist\n";
exit(1);
}

STDOUT->autoflush(1);

foreach my $filename (glob("$srcdir/*")) {
if (-f $filename && -r $filename) {
my ($name, $path, $suffix) = fileparse($filename);
`metapixel $opts --prepare $filename $destdir/$name$suffix.png $destdir/tables`;
print ".";
}
}
16 changes: 9 additions & 7 deletions metapixel.c
Expand Up @@ -587,15 +587,18 @@ generate_search_coeffs_for_subimage (search_coefficients_t search_coeffs[3], flo
{
int j;

x /= small_width;
y /= small_height;
if (small_width != IMAGE_SIZE || small_height != IMAGE_SIZE)
{
x = x / small_width * IMAGE_SIZE;
y = y / small_height * IMAGE_SIZE;
}

for (j = 0; j < IMAGE_SIZE; ++j)
for (i = 0; i < IMAGE_SIZE; ++i)
{
float_image[(j * IMAGE_SIZE + i) * 3 + 0] = DownScale(image->pixels[(y * IMAGE_SIZE + j) * image->columns + x * IMAGE_SIZE + i].red);
float_image[(j * IMAGE_SIZE + i) * 3 + 1] = DownScale(image->pixels[(y * IMAGE_SIZE + j) * image->columns + x * IMAGE_SIZE + i].green);
float_image[(j * IMAGE_SIZE + i) * 3 + 2] = DownScale(image->pixels[(y * IMAGE_SIZE + j) * image->columns + x * IMAGE_SIZE + i].blue);
float_image[(j * IMAGE_SIZE + i) * 3 + 0] = DownScale(image->pixels[(y + j) * image->columns + x + i].red);
float_image[(j * IMAGE_SIZE + i) * 3 + 1] = DownScale(image->pixels[(y + j) * image->columns + x + i].green);
float_image[(j * IMAGE_SIZE + i) * 3 + 2] = DownScale(image->pixels[(y + j) * image->columns + x + i].blue);
}
}

Expand Down Expand Up @@ -975,8 +978,7 @@ main (int argc, char *argv[])
}

out:
generate_search_coeffs_for_subimage(search_coeffs, means, image,
x * small_width, y * small_height, use_crop);
generate_search_coeffs_for_subimage(search_coeffs, means, image, x, y, use_crop);

pixel = metapixel_nearest_to(search_coeffs, means);
paste_metapixel(pixel, out_image_data, in_image_width, in_image_height, x, y);
Expand Down
8 changes: 0 additions & 8 deletions prepare

This file was deleted.

24 changes: 24 additions & 0 deletions rwpng.c
@@ -1,3 +1,27 @@
/* -*- c -*- */

/*
* rwpng.c
*
* metapixel
*
* Copyright (C) 1997-1999 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <assert.h>
#include <stdlib.h>

Expand Down
24 changes: 24 additions & 0 deletions rwpng.h
@@ -1,3 +1,27 @@
/* -*- c -*- */

/*
* rwpng.h
*
* metapixel
*
* Copyright (C) 1997-1999 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __RWPNG_H__
#define __RWPNG_H__

Expand Down
22 changes: 17 additions & 5 deletions vector.c
@@ -1,13 +1,25 @@
/* -*- c -*- */

/*
* $Log: vector.c,v $
* Revision 1.1 1999/12/26 19:44:05 schani
* Initial revision
* vector.c
*
* Revision 1.1 1997/12/28 17:30:30 schani
* Initial revision
* metapixel
*
* Copyright (C) 1997-1999 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <math.h>
Expand Down
22 changes: 17 additions & 5 deletions vector.h
@@ -1,13 +1,25 @@
/* -*- c -*- */

/*
* $Log: vector.h,v $
* Revision 1.1 1999/12/26 19:44:05 schani
* Initial revision
* vector.h
*
* Revision 1.1 1997/12/28 17:30:05 schani
* Initial revision
* metapixel
*
* Copyright (C) 1997-1999 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

typedef struct _Vector2D
Expand Down

0 comments on commit 6129962

Please sign in to comment.