Python Forum
Pillow Image Processing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pillow Image Processing
#1
I'm a Sega Genesis homebrew developer. I want to write a script to optimise images for the console. I'm hoping to use the Pillow library but don't even know if what I have in mind is possible!

I'd like to take a single image of 216 x 120 with 60 colours. For every 8x8 pixel square (tile) i'd like to take a colour palette and store this in an array of palettes. In an 216 x 120 image there are 405 tiles.

Once I have all 405 tile palettes, I'd like to compare each palette with the next in the array and if they're identical, I'd like to pop the palette off the array and eventually leave myself with a set of unique palettes. I'd then like to whittle these final palettes down to 4 by comparing each tile and finding its palette of best fit.
Reply
#2
It's posible
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
I don't have a complete solution for your problem. You should use Pillow and Numpy for this task.

For the beginning you can open the picture and save width and height and channels in three variables.

from PIL import Image

img = Image.open('your_img.jpg')
w, h, c = *img.size, len(img.getbands())
# img.width, img.height to be more explicit
Then you need to put you image into a numpy array.

arr = np.fromstring(img.tobytes(), np.uint8)
# then reshape it.
arr = arr.reshape((w, h, c))
I think this should you give all tiles with a size 8x8 with 3 colors.

tiles = arr[::8,::8,:3]
The array tiles should have a shape of (width//8, height//8, 3).
But this is only the half work.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  grayscale image processing zyb1003 10 7,875 Oct-26-2017, 05:33 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020