Page 1 of 1
Polaroid rotation randomness (lack of)
Posted: 2009-01-20T12:41:18-07:00
by arizonagroovejet
I'm using the code below to produce a bunch of images where the source photo has been given the polaroid treatment and had an image of a randomly selected thumb-tack added to it. The use of +polaroid is supposed to give a randomized angle. (
http://www.imagemagick.org/Usage/thumbnails/#polaroid)
However I'm finding that the randomness, well, just isn't really. On a batch of 20 images they'll be two maybe three different angles used in the whole bunch and always with the image tilted to the left. I'm also getting identical results on successive runs. I.e. If I run the code three times and then compare the three sets of resulting images then they're identical. Or at least they're identical as far as my eyes can tell.
Anyone have any insight in to why the randomness is so lacking and/or how to get some better randomness? I'm using openSUSE 11.1 x86_64, ImageMagick 6.4.3.
Code: Select all
for i in photos/*.jpg;do
pfn=`basename $i | sed 's/.jpg//'`
pin=`ls pin_*.png | sort -R | head -1`
composite -matte -gravity North ${pin} $i jpeg:- | convert - -bordercolor snow -background black +polaroid with_pin_${pfn}.png
done
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-20T12:44:25-07:00
by magick
The angle is random within 15 degrees. We can change that to anything from 15 to 360 degrees. What do you suggest?
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-20T13:33:03-07:00
by arizonagroovejet
Thanks for the reply, but I'm rather confused by it.
magick wrote:The angle is random within 15 degrees.
Except for me it's not. Like I said the results are only ever tilted to the left and there is no real randomness. A random rotation within the range of +/- 15 degrees would be fine, but like I said, I'm not getting anything like that. In when I said I got maybe two or three different angles that was based on yesterday's experience. Running the code just now I get the same angle of rotation every single time. This is a screen grab of what I'm getting.
It's not great, but it's clear enough to see that all the images are rotated the same amount.
magick wrote: We can change that to anything from 15 to 360 degrees.
How can it be changed? Not that I want to change it right now, but it could be useful to know in future.
reveals that the image is in fact always rotated by the same amount regardless of the angle I specify. E.g. if I specify an angle of
magick wrote: What do you suggest?
I don't understand... what would you like me to suggest?
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-20T14:19:28-07:00
by magick
We're clueless why it fails for you. We ran the +polaroid option multiple times and it returned these angles:
- 6.28852
-5.11265
-3.48736
-5.63954
4.98868
-2.59783
-5.19191
There is not enough data to prove its random but it sure looks random. We're using ImageMagick 6.4.8-7.
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-20T15:00:08-07:00
by Bonzo
This is an image I made using the standard poleroid settings:
Looking at this image 7 out of 12 images are lower on the right but that may change on another run.
Could you use -poleroid and generate a random angle to insert into your code arizonagroovejet?
Can you try your code on another computer and see what the results are - my image above was on a windows PC using php on a localhost setup.
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-20T15:39:59-07:00
by arizonagroovejet
magick wrote:We're clueless why it fails for you. We ran the +polaroid option multiple times and it returned these angles:
How do you get that info?
Bonzo wrote:
Could you use -poleroid and generate a random angle to insert into your code arizonagroovejet?
Yeah I could if need be.
I did just try it the same commands on another machine - a Mac with ImageMagick 6.4.3 installed via MacPorts. I got the expected results on that machine. So I installed a virtual machine with openSUSE 11.1 - I get the expected results on there too. The only difference is the virtual openSUSE and the real one it's running on is the virtual one is running 32bit openSUSE 11.1 and my real machine 64bit. For some reason VirtualBox wouldn't let me install 64bit openSUSE claiming my computer was 32bit even though it's running 64bit openSUSE and I installed the 64bit version of VirtualBox.
So... what the %$*%! is going on on my 64bit openSUSE machine.
When I'm at work tomorrow I'll grab a spare machine, put 64bit openSUSE on it and see what happens.
Thanks for the replies so far.
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-21T13:47:22-07:00
by arizonagroovejet
So I zipped up the script I'm using and the test images, took them to work, installed openSUSE 11.1 64bit on a spare machine, ran the script and got.... randomly rotated images.
Came home from work, ran the script again on my openSUSE 11.1 64bit machine and got... same as yesterday. Every image barely rotated and always by the same amount. Un-installed ImageMagick package and re-installed it but no change.
So it seems the problem is unique to my machine, but I have no idea why.
Oh well, looks like I'll just have to manually generate a suitable random number and use that with the -polaroid option.
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-21T14:00:37-07:00
by Bonzo
Thats strange - I wonder how Imagemagick actualy generates a random number ?
With your code - I have no idea how it works or what it is
can you generate a random number automaticaly ?
Code: Select all
for i in photos/*.jpg;do
pfn=`basename $i | sed 's/.jpg//'`
pin=`ls pin_*.png | sort -R | head -1`
composite -matte -gravity North ${pin} $i jpeg:- | convert - -bordercolor snow -background black -polaroid [random_number] with_pin_${pfn}.png
done
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-21T14:09:50-07:00
by magick
The pseudo random generator is seeded with a crytographically strong initial seed (the seed is generated from various sources including /dev/random, time of day, the environment, etc.) and then we return a non-negative double-precision floating-point value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period.
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-22T12:19:36-07:00
by arizonagroovejet
Bonzo wrote:
With your code - I have no idea how it works or what it is
can you generate a random number automaticaly ?
It's just bash script and yes, I can generate a random number and use that. Bash has a random number generation via the $RANDOM varaible, e.g.
Code: Select all
mike@continuity:~$ echo $RANDOM
22433
mike@continuity:~$ echo $RANDOM
17144
mike@continuity:~$ echo $RANDOM
10827
which you can then manipulate down to the desired range but better for my needs is a bit of perl which someone else suggested to me. I don't really understand how it works, but it gives as number between 15 and -15.
Code: Select all
r=$(perl -e 'print int(rand() * 30) -15')
composite -matte -gravity North ${pin} $i jpeg:- | convert - -bordercolor snow -background black -polaroid $r with_pin_${pfn}_2.png
Actually seems to gives a more pleasingly random result that +polaroid does when it does work, but that may be just my imagination
Re: Polaroid rotation randomness (lack of)
Posted: 2009-01-22T13:42:27-07:00
by magick
The polaroid effect ranges from -7.5 .. 7.5. We increased it to -15 .. 15 degrees in ImageMagick 6.4.8-9.