LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-19-2009, 01:59 PM   #1
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Imagemagick polaroid rotation randomness


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 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:
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
 
Old 01-20-2009, 09:36 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Well, I don't really know much about it, perhaps the +polaroid option is just not that flexible, but the link you gave seems to provide the workaround. Just manually set the rotation instead with a random number generating command, such as the perl expression he provides: "-rotate $(perl -e 'print rand() * 30 - 15')"

I also have a bit of advice for your script. Assuming you're using bash, you should use the $() operator for embedded commands rather than `backticks`. It's more readable and works better in some cases. Also, instead of using the awkward sed-based command to change the file extension, you can use parameter substitution instead. For example "${i%.*}.png" will strip off the file extension from the variable (everything from the last period) and add .png to it.
 
Old 01-21-2009, 07:35 AM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Original Poster
Rep: Reputation: 198Reputation: 198
I have made some progress with this now. See http://www.imagemagick.org/discourse...hp?f=1&t=12961
for details. Though yet to figure out why it doesn't work properly on my main machine.

I'm aware of the use of $() , my use of backticks is a long standing habit I've yet to be bothered to try and break.
Similarly for sed. I know about the parameter substitution but learnt the sed way first (wrong though that may seem!) and tend to use it unless I happen to remember the bash method at the time.

Thanks for that bit of perl - that's very neat. Better than the bash method I was using to manual generate a random number as it produces both positive and negatives numbers. I may well end up using that instead of the +polaroid option as even when the +polaroid option does work I think the result might be more pleasingly random using the perl generated numbers.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Randomness codfreek General 53 03-13-2008 10:21 AM
Mouse Randomness VyrusNine Linux - Laptop and Netbook 0 06-06-2006 08:26 AM
Polaroid PDC1300 jtravnick Linux - Hardware 1 07-31-2005 06:16 AM
The complete random randomness thread beajedi General 72 04-13-2004 05:32 PM
AC 97 audio chipset + OSS + complete randomness Mad Merlin Linux - Hardware 2 09-05-2003 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration