Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2012, 03:17 AM
jepot jepot is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 17 jepot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 17 m 23 sec
Reputation Power: 0
Divide image into 6 parts

Hi, I have an image which has a certain height n pixels. I would like to divide this to 6 parts so that each part has a height of n/6 pixels. The length will be the same for each. How would I be able to achieve this? Currently I have the Python Imaging Library imported, then have the ff:

Code:
im = Image.open('somepic.bmp')


for example, if somepic.bmp has a height of 270 pixels, then it will be divided into 6 images each with a height of 45 pixels.

Reply With Quote
  #2  
Old July 3rd, 2012, 11:00 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,362 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 15 m 29 sec
Reputation Power: 383
I've never used PIL. I suppose your project is possible as stated. Anyway, install imagemagick, bash, and gawk if you haven't already got them. Write the following shell script into the file windowBlinds.sh , change the mode to executable, then run with the command

path/windowBlinds.sh NameOfPicture.picture_type

For example, I tested using the Bourne again shell command:

./windowBlinds.sh BrideAndGroom.jpg | bash

it made the pictures, correctly, as
0BrideAndGroom.jpg
1BrideAndGroom.jpg
2BrideAndGroom.jpg
3BrideAndGroom.jpg
4BrideAndGroom.jpg
5BrideAndGroom.jpg

Code:
identify $1 | gawk --assign NAME="$1" '{split($3,size,/x/);for(i=0;i<6;++i){printf"convert -crop %dx%d+0+%d %s %d%s\n",size[1],size[2]/6,i*size[2]/6,NAME,i,NAME}}'


Imagemagick handles a great many picture formats. I've written the code to give output in the same picture format as input---because it's easier and you didn't give other instructions. convert uses an internal form so can input one picture format and output another without trouble.

[Edit: this solution reloads the picture 6 times. If you need to do this in real time or if performance is an issue for whatever reason, a gimp script or the PIL might be preferable. Actually, imagemagick features a language as well so you could probably do it using the magickwand.]
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : July 3rd, 2012 at 11:23 AM. Reason: clarification

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Divide image into 6 parts

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap