So this week I have been doing this image processing online course:
https://www.futurelearn.com/courses/robotic-vision-processing-images/2/todo/29218
But they were getting you to do the tasks in Matlab, which i don't find very satisfying because I don't know the matlab functions very well and I can't incorperate it into other projects. So the process of this project was very similar to when I watched a tutorial for an algorithm in javascript and wrote it in python to further my understanding of both languages as well as my understanding of the algorithm.
Posterisation of an image changes continuous gradation of tone to abrupt changes from one tone to another because there is only a select amount of tones in the whole image.

The blue line is if nothing changes to the pixel, and the red line is what happens to the pixel's grayscale number when you posterise it. You can see that the continuous values of grayscale allowed is now only a couple of different values. The function mentioned in the course was N*floor(x/N), N being amount of different tones and x being the current pixel value.
I wanted to use python with the pillow module because it is an easy way to manipulate images and save them. In pillow you have a grayscale between 0-255 not 0-1, so I would have to map the values to between 0-1 for their function to work, but it was unclear how their function even works because if you floor numbers between 0-1 it will always result in 0...
So I came up with my own solution to this:
so for example, if you wanted 10 tones you would want everything to be rounded down to every 255/10 = 25.5 increment. So i made a function that rounds a number down to to it's nearest increment of a certain number, for instance rounddown 50 to the nearest 20 would answer 40.
So here is the code:

I did loads of different amount of steps so that i could see the differences. You can ingore what i save the pictures as because it doesn't matter what you name them, but if you name them the same thing it might replace each picture when it saves the next one.
Here was my best result:
Original:

N=3:

N=6:

N=9:

You can see the differences between different values of N.
The only thing I would change about this project is round up and down instead of just rounding down. I would recommend trying this yourself aswell. I really enjoyed doing this project because it was something only talked about for 20 seconds on the course, but i thought it was a really cool concept and looked into it further to right my own algorithm for it.
Thankyou for reading!
:)
コメント