The idea
So while on deep learning workshop in Melbourne. I was playing around with tensor flow and seeing it was really easy to do convolutions over images with it. (Workshop was at Silverpond and would highly recommend it)
So in short convolution is comparing two signals with each other the more they resemble each other the stronger the result.
This makes for super signal filters btw.(Electronic engineering for the win)
I remember seeing this trick in an old textbook called the Sobel_operator and wanted to give it a try.
The sobel operator is basicly an edge detection on image. But what I wanted to do it in horizontal and vertical direction then form a vector. I could then colour the image based on direction of the edge to make pretty images.
Loading image and libaries
For the image i picked a very plain cup with very clear edges. An image with heavy texture will have to many edges detected and not look as impresive.
|
|
Note when installing tensor flow for the first time. Use the CPU version getting the GPU version to work took me a while getting all the correct version loaded and working together.(Think its even easier on AWS as there are prepared images)
Doing calculations
So the next code block I’m setting up the object in tensor flow. it isnt activated just yet. Its basicly building a pipeline for information to flow through. Note the 3 by 3 sobel vectors in code for horisontal and vertical.
|
|
I the next code block i activate the tensor flow session doing the calculations and producing our output vectors.
|
|
Going some trigonometry
So time for some trig to calculate the strength and angle of the vector.
First we calculate the streng as shown in this image.
This was generated using the following code. (plain old Pythagoras)
Next we calculate the angle of the vector. Note that this image always has a value or angle.
In low strength areas its very noisy as the ratio between x and y swings easily. (a signal to noise example)
Its calculated with following code. I added very small value to avoid divide by zero issues. (Samll cheat alwas productive)
|
|
Final result
So in the end we combine the two.
We do this by having a strong angle for red , green and blue. Done by diffrent offsets in cosine value.
its also important to normalize each value.
|
|
Just by shifting angles between colours you can change image vector
So in summary I really enjoyed getting to do this algorithm as i remember seeing it and wanting to replicate it.
Its important to note that shadows will get picked up as edges.
But i was also wondering if you have enough images from diffrent direction you can generate a polygon :p
Ive uploaded the notebook to my git if you want to give it a try.
Im thinking ill do a RNN next.