By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

Changing 1/3 of a picture to different colour using python

P: 6
I have some code so far, but I need it to only be applied to the bottom third of a photo, it is taking all the black spots in a photo and changing them to yellow. I just need it to only be applied to the bottom 1/3 of the photo. Here is the code I have right now:
Expand|Select|Wrap|Line Numbers
  1. def change(pic, startX, startY, getHeight, getWidth, endColour): 
  2.   width = getWidth
  3.   height = getHeight 
  4.   picture = makePicture(pic)
  5.   for px in getPixels(picture):
  6.     x = getX(px)
  7.     y = getY(px)
  8.     if (startX <= x <= getHeight) and (startY <= y <= getWidth):
  9.       if (distance(black, getColor(px)) < 95):
  10.         setColor(px, endColour)
  11.   show (picture)
  12.   return (picture)
[/python] [/pixels] [/color] [/forLoop]
Nov 3 '15 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 621
You simply count the pixels as you process the picture, divide by 3, and make another pass, ignoring everything until the count hits the bottom third.
Nov 4 '15 #2

P: 6
right, I am just not sure on how to incorporate that into my program.... I could get it to do the top third but that was as far as I got, and I need to top third to be untouched. With the middle third red and the bottom third yellow.
Nov 4 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.