Friday, November 28, 2014

Afbeeldingen bij Volkskrant stuk van 29 nov 2014

Als aanvulling op het stuk in de Volkskrant over de zelfrichtende zonnebloem wilde ik hier wat foto's laten zien, het elektrische schema en een kort filmpje.
Daarnaast zal ik een afbeelding plaatsen die ik zelf als zonnewijzer heb gebruikt. Ik heb een formule van Wikipedia gebruikt om de hoek tussen de uren te berekenen. Ik heb het één keer getest en toen was de afwijking ongeveer tien minuten wat ik aanvaardbaar vond.
Vragen zijn altijd welkom.



In de bovenstaande video zie je eerst hoe de bloem reageert als er niks van stabilisatie is. De motor draait op vol vermogen en schiet daardoor steeds te ver door. Hij beweegt daardoor heel wild. Daarna heb ik een kunstmatige vertraging toegepast door de motor steeds maar heel kort (10 ms) aan te laten en vervolgens weer uit te zetten.

Het initiële idee voor het gehele elektrische schema.
De weerstand van de LDR's is echter te groot om nog voldoende stroom te krijgen

Twee LDR's met weerstand, de feitelijke sensoren.


Het uiteindelijke elektrische schema.
Het sensor deel (boven) is nog hetzelfde maar de spanning gaat nu naar de Arduino.
De Arduino beslist dan welke transistoren in het onderste deel open mogen (pretty nice)
10 en 11 of 12 en 13 gaan tegelijk open.

Schakeling in test opstelling. Het bovenste breadboard bevat de LDR's,
de onderste de vier transistoren die de stroomrichting van de motor besturen



Definitieve opstelling in een houten doos





Zonnewijzer die onder de bloem geplaatst kan worden. Of gewoon op je vensterbank.
12 uur moet naar het zuiden gericht worden. Geschikt voor 520 NB en wintertijd.

Saturday, November 1, 2014

Foto's en Video's bij mijn Whack-A-Mole stukje uit de Volkskrant



Dit zijn wat foto's die ik gemaakt heb tijdens het maken van het Whack-A-Mole spel, of eigenlijk, Mep-Een-Vlieg waarover ik een stukje heb geschreven in de Volkskrant van 1 november 2014.

Als je geen papieren versie te pakken hebt gekregen is het artikel te vinden via de Volkskrant website of bijv. via Blendle.

Mocht iemand zelf een Mep-Een-Vlieg Spel willen maken, de foto's hieronder geven al een goed beeld van wat je moet doen. Als je nog vragen hebt stel ze dan vooral.

Allereerst een korte video van dochterlief terwijl ze het spel probeert.




Close up van mijn tekenkunst
Bovenaan het zilverfolie een groene LED
die door de folie prikt om het te verbinden



Enthousiast uittesten (maar echt hoor)

Serieus, ze vond het heel leuk,
maar het was 7:30 's ochtends

Binnenkant van de doos.
Boven in beeld de speaker
Schematisch schema

ENGLISH
These are some pictures I made during the making of my own Whack-A-Mole (Fly in this case).
I made this project for my article in de Volkskrantof 1st november 2014.
Questions are always welcome.

Thursday, October 23, 2014

Zelfsturende Auto (foto's bij het Volkskrant stuk)

(English below)
Op zaterdag 3 oktober verscheen in De Volkskrant mijn eerste bijdrage in 'De Maakbare Wereld' in de zaterdag Sir Edmund katern. (te vinden op de Volkskrant website of bijv Blendle de eerste zoveel artikelen kun je gratis lezen)
Hier heb ik kort uitgelegd hoe ik een afstandsbestuurbare auto met mijn laptop kon besturen.
Een volgende stap is natuurlijk dat er geen persoon meer aan te pas komt. En ik heb daar al een groot deel van geknutseld, maar nog geen tijd gehad om de puntjes op de i te zetten.

Wat ik in elk geval wilde delen waren de foto's die ik gemaakt van tijdens het werken aan de auto. De foto's waar de toffe tekeningen op gebaseerd die gemaakt zijn door Bier & Brood.

De auto en wat belangrijke werkspullen

Testen waar spanning op gezet moet worden



Draden gesoldeerd in AB en via wat transistoren (kleine zwarte dingen) op
een breadboard (witte ding) naar de Arduino (blauw ding)

Als iemand specifieke vragen heeft, stel ze. Dit is niet een enorm ingewikkeld knutsel project en zeker niet duur. In dit geval is de Arduino het meest kostbaar en een autootje is natuurlijk niet gratis.

Het lastigste is in zo'n geval het uittesten hoe de afstandsbediening nu precies werkt. En dat testen heb ik gewoon gedaan door te kijken hoe zit de batterij aangesloten (waar gaan de plus en min heen) en gewoon wat met de 5 Volt uitgang van de Arduino en twee draden proberen. Kleine kans dat je iets stuk maakt met die 5 Volt, want de batterij die er inzat was een 9V blok.

En gaat er een keer iets stuk dan heb je ook iets geleerd. Gebruik dus spullen waar bij het niet erg is dat ze stuk gaan.

Misschien een goeie tip voor Sinterklaas: vraag een soldeerbout en wat weerstanden :)


ENGLISH (very short summary)

I wrote my first newspaper article about controlling a RC car with my laptop. These are some pictures I made while making the project.
If you have any questions, ask them.

Sunday, August 10, 2014

Ebola Outbreak 2014

Ever since I first heard about the Ebola virus I have found it very terrifying. Who wouldn't with high infection chances and survival rates being low and no cure (apart from the stories about a 'secret medicine' in the US only tested on animals). Since March news items regularly hit the news of an Ebola outbreak in West Africa. Countries that are hit the worst are Guinea, Liberia and Sierra Leone.

Source: Wikipedia


But news items usually state the total number of casualties so far or some recent events, but they somehow don't manage to show me how serious the situation is. So I went to the WHO site on the subject. Here they have posted news updates. So I went through them all to get the overview myself.


Countries in Western Africa involved in Ebola outbreak
Below is, as at the time of writing, the most recent overview by the WHO. You can see that luckily Nigeria still hasn't had that many cases, but the other countries are not that lucky. There were reports about cases in Mali, but they were tested negative.


New (1)ConfirmedProbableSuspectTotals
Guinea
Cases03551337495
Deaths42311333367
Liberia
Cases38148274132554
Deaths1213211745294
Nigeria
Cases407613
Deaths10202
Sierra Leone
Cases266313848717
Deaths12259345298
Totals
Cases681 1344521931 779
Deaths2962228653961
1. New cases were reported between 5 and 6 August 2014.
source: WHO aug 8 2014

This of course only tells you part of the story. The Wikipedia on the 2014 outbreak is very elaborate on the matter and it has a nice graph of the totals. To get an impression how different countries are doing I put the data I took from the WHO site in a graph.


In this graph you see the total number of cases. That includes confirmed, deaths and suspected cases.
The graph tells a sad story of course. in Guinea the outbreak started and slowly the number of cases is increasing. But for Sierra Leone and Liberia it looks a lot grimmer. The number of cases is really exploding, so let's hope they are able to stop this soon.

I choose to use circles in this graph and not a continuous line. It seems more transparent. The data isn't continuous in any way. The information comes with a couple of days apart, it's changed constantly when tests are negative and of course people come in whole numbers. So in Liberia in April there were some suspected cases they turn out not to be due to Ebola. In result the total number was lower in May.

Death rates are always really high with Ebola and this outbreak is no exception. Guinea: 74%, Liberia: 53% and Sierra Leone: 41%. Those number could go up I guess since there some time between showing signs of the virus and when people pass away.



Monday, July 7, 2014

Reducing the Number of Colors (Part I)

In my last post I discussed a way to reduce the number of colors in grayscale image. So the natural step was to proceed to a color image. Let's start with a nice color image.




The color image is just a collection of a red, a green and a blue image.


The Ignorant Approach


The first thing I tried, just to see what would happen, was to try the algorithm I made for the grayscale image. That means repeating the process for the individual channels and later merging the result.
That works, but it doesn't give the result I am really looking for.


For some colors this approach works. The sky is a nice color blue, some bright yellow accents on the plane come out as I wanted, but some color like on the right wing seem wrong.
What the program found were 6,6 and 7 peaks for the color channels. That means that if a certain value of blue is very dominant that value will be picked. But the area that belongs to that color might not be purely blue.

Similar But Different

Here's an example of 6 colors with the same maximum blue value of 255, but with different red and green values.

Square with different RGB values, but the same blue value.

You can imagine that one of these colors is not found as a dominant. If a certain color is found it has to give rise to a peak in he histogram of all three colors.


The picture above is an example in two color dimensions, the x-axis representing green and the y-axis blue. The dots are both colors that occur in some image. But perhaps the one in the top is found in way more pixels then the one in the bottom. In the end the green value which is the same for both colors will be found probably. But the blue value of the lowest color might not be found. Every pixel with a color close to that bottom color will be assigned a green value that is correct, but the new blue value could be miles off.

3D RGB Space


For me the problem was beginning look a bit clearer, also a bit more difficult. When you look at all the colors that occur in an image there are thousands. Some are quite similar, like all those colors blue in the sky of our example image. Let's see what all these colors look like in the 3D RGB space.

3D RGB Space of the Spitfire image

What I have drawn here is all the pixels in the image placed in the RGB space. Easily understandable points are (0,0,0) which is black in the front and (255,255,255) as white in the back. Along the diagonal axis are all the gray colors. Off diagonal RGB values are the other colors, and you can see some groups, and a lot of empty space. What you can't see how many identical RGB points there are, and how many of are all alone.
That is why I made the same image but here I changed the size of the circles to show how many pixels have that color.




We are looking at it from a different angle, but it shows one thing; there are a lot of blue pixels.

That's about as far as I've come right now. What I intend to do next is to find the regions of this image where a lot colors are found close together (like that blue area in the top). So this is similar to finding a peak in 1D histogram, but than more like finding a 3D peak (a blob with the highest density).
I am still thinking of what the best approach is going to be for this. 

Stay tuned!









Tuesday, July 1, 2014

Reducing the number of colors in an image

OK first all, one of my most favorite astronaut pictures showing Anna Lee Fischer. To me it looks it's from a movie or something, it's just that cool.

Anna Lee Fischer

Long story short, I was wondering if I could reduce the number of colors (the grays) in this picture. Just for fun and exercise. I could try an image/photo editor, but it's always more fun to do it yourself right.

I went to work in Matlab and to just show you the end result first (before all long boring programming details). Tadaa!

Only 5 grays left


How it's done

The main idea I had was finding the colors that are most dominant. We therefore look at the histogram of the image as shown below. Values run from 0 to 255 on the x-axis and the y-axis represents the number of occurrences of a certain gray value in the image.



Something I find strange are the very regular holes in the histogram where a certain gray value apparently never occurs. Apart from that it's not a smooth line, there are about 5 local maxima visible. 
How do we find those?

Finding the peaks

I first removed the holes by using the average of the gray values around it. After that I applied a Gaussian smoothing. Before I tell you about how I find the peaks I'll first show the result of smoothing and finding the peaks.


You can see that the line is now very smooth and there are small red lines to show where the peaks are found. I find it a very satisfactory result. It may seem like the first and last line are just a bit off, but that is only because the steps are integers and the lines are placed on the integers. So i.e. to me and you the peak should be at 18.7, but it is found at 19.

The short explanation of how the peaks are found is this. I let the program walk along the line until it reaches the top. That means the next position has a lower value instead of a higher value. After that we continue to find the valley, so look for a position where the next element is higher instead of lower. And we go back to finding the next peak. I'm only interesting in the peaks of course. I don't tell the program how many peaks there are, just to stop when it's at the end of the histogram. 

Changing the colors 

To create the new image I take the value of every pixel in the original image and look to which peak value it is closest. Then it is changed to that peak value with a preference to the lowest/darkest value. The original image was pretty noisy so you can see this in the end result. 

When you use this method you have no control over how many colors the end result will have. This can be an advantage or a disadvantage depending on your needs. But I like it that we don't put in any previous knowledge and the program itself finds the most dominant values.

I guess this whole process or parts of it has a name, but it was still nice to built myself from scratch.

I'll try how the program works with color images, which will need some adjustments.





Tuesday, June 24, 2014

Presidents in books

I just read about Ngram Viewer. A Google project where you can search for words of phrases in books Google has digitalized. Here I search for presidents of the United States, from FDR till Jimmy Carter. Non interactive picture:

Monday, June 23, 2014

Summation Trick for Object Recognition

In this article I want to explain a feature of the blob detection I built.
I've been working on my autonomous boat project and what I needed was a way to detect where the boat was and where it was going. I chose to put bright stickers (green and blue) on the boat. Here's a nice picture of me testing out the detection algorithm.

Program recognizes a green and blue spot on the paper


Binary images

The beginning of finding these object is simple. The video images from the webcam have three color channels (red, green and blue). So the first step in this process is to look at pixels and decide if we find them particularly green (I'll talk about green, but you can replace it with blue and you get the same story). If this is the case we assign a 1 to that pixel and otherwise we assign a zero, so we get a binary image.
There is a big possibility that there are some pixels that are green, but don't belong to the sticker I'm looking for. We do know that the middle of the sticker is probably surrounded by a lot of green pixels.

Think of it this way, if I could add up all the pixels in my binary (1's and 0's) image around some pixel I'll know if I'm looking at a green area or not. If the sum is small it was just some stray green pixel, if the sum is really high I've found a really green area. I'll try and find the pixel which gives me the most green neighbors and decide that that pixel is the middle of sticker (or close enough).

Sound easy, but it felt like the computation of all those sums could be to heavy to perform in a real-time video. To estimate how many calculations that is. Say we have a 800 by 600 video image (small) and we look at an area of 10 by 10 pixels around every pixel (small again). That means roughly 800*600*10*10=4.8 million pixel additions!

I don't know if Processing can handle that at 30 frames per seconds, but I didn't want to try when I already knew a way to speed it up by a factor of 25. Not possible?

Less is more

I'll explain the method I used in one dimension first before I explain the 2D image method.

Imagine you have a vector of numbers i.e. U = [2, 5, 7, 1, 3, 2, 8, 6 , 7, 2, ....] and you want the sum of 10 consecutive numbers in this vector, for every position.

To make it clear I give the positions a name 1, 2, 3, etc.



So this sum I am looking for is  
V=[1+2+3+4+5+6+7+8+9+10,   2+3+4+5+6+7+8+9+10+11,  ....].

Instead of doing this directly we take an intermediate step. We construct the following vector:



As you can notice the first sum I am looking for can already be found in position ten of this new vector. In position eleven we find 1+2+3+4+5+6+7+8+9+10+11, which is almost the second sum we are looking for. So have so subtract 1 which is found in position one of our new vector.
Last example: in element twelve we find 1+2+3+4+5+6+7+8+9+10+11+12, where the 1+2 are too much. This is found in the second element of the vector w.

As you hopefully understand know. You only have to look at two numbers in our intermediate vector and subtract them to find the sum of four numbers. How much does that save in total calculations?
Building the intermediate vector costs 2*n additions
pseudocode:
     w(1) = v(1)
     for i = 2:n
          w(i) = w(i-1) + v(i)
     endfor

And after that the summed vector s takes another 2*n additions
     s(1) = w(10)
     for i = 2:n
           s(i) = w(i+10)-w(i-1)
     endfor

So that brings the total to 4*n numbers that need to be added. If we had done it in the normal fashion it would have been 10*n additions.
The more numbers that needed to be added, the more you save. 

More of that


But what about 2D? We want the sum in a whole around a pixel. Again we have to take an intermediate step to reduce the number of additions. I usually think of an image as a big matrix, so imagine one where every position has number as a name.



In this example the rows are 100 elements long, but that doesn't matter. We'll call the new intermediate matrix N and the first row will look very familiar now:

[1, 1+2, 1+2+3, 1+2+3+4, ....]

The second will be filled as follows [1+101, 1+2+101+102, 1+2+3+101+102+103, ...]. What we have done is adding elements again from the second row in M, but also add the element that lies above in N. The very last element in the matrix N while have the sum of all the elements of M if we continue like this.



One example should show how easy it is to find the sum of an area now.  Say we want the sum of the elements in squares 102, 103, 202 and 203. This is a simple example that doesn't speed up, but it is easier to understand.
Let's look the third element in the third row. It has these four numbers added we are looking for. But also a couple to much (1,2,3, 101 and 201). The first can be removed by subtracting the square in blue. 101 and 201 can be removed by substracting the square in purple. You see that we subtract 1 twice, but we can correct this by adding the red square.


Ok, in this example we add and subtract four numbers when we could have added the four numbers directly.
But if you wanted to have the sum of a ten by ten area the calculation would still only involve four numbers ,instead of a hundred (tadaa factor 25!!). 

For a position i,j in an image for an area of n by n pixels the sum becomes:



For me it's an old trick, but maybe someone finds it useful. I still find it satisfying when I find an opportunity to use it.