color matching for pattern - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html) +--- Forum: Parts Author Tools (https://forums.ldraw.org/forum-24.html) +--- Thread: color matching for pattern (/thread-11491.html) |
color matching for pattern - Michael Heidemann - 2014-01-01 Sometimes I am also looking for new possibilities for creating pattern. One of the challenges I am faced is to reduce the colours used in that pattern. This is mainly necessary because most (if not all) pictures are antialiased and therefore we do not have sharp edges that we can work with, if we try to automatic the generation of pattern in ldraw file format. I tried it so far with an algorithm from bitsticker project: Code: ''' Identify the most similar color in the palette to a specified color based I remembered that Tim some time ago argued that the colors are not recognised by the eye in the same way (blue different than red etc.). So I searched on the internet for calculation of color differences. I found a source for many color related stuff at: http://www.brucelindbloom.com/index.html?ColorDifferenceCalc.html Sadly I did not get yet a key idea from that information. But I could read that the algorithm I used so far is known to be not good. Maybe some can read and understand that, so he can tell me how to calculate the color differences better. This should lead to a better color matching in automatically created pattern. I think this is a good task for 2014 Re: color matching for pattern - Tim Gould - 2014-01-01 Hi Mike, What you're after is a colour quantisation algorithm. Ideally based on the lab colour space model but more practically based on YUV colour space. In the pseudo-code I use YUV as it is much, much easier and we are not seeking perfection. Or in pseudo-code we find the square of the distance via: Code: # Here T converts RGB -> YUV (and inverse(T) converts backwards) Note that the red and green components are more important (especially green) than red. This is because our eyes are much better adapted to seeing green - I guess because grass and trees are more common than blueberries. Hope that helps Tim Re: color matching for pattern - Michael Heidemann - 2014-01-01 Yes, I think that is what I am looking for. Given the current code is like this taken from bitsticker project Wrote:# I only need to incorporate your pseudo code into this one (hopefully i am not too stupid). Thanks so far for your answer. I hope this will solve some (or all) of my current issues Re: color matching for pattern - Tim Gould - 2014-01-01 Just need to change one line Code: $dist = 0.489235*($dr * $dr) + 0.693315*($dg * $dg) + 0.213092*($db * $db) Re: color matching for pattern - Michael Heidemann - 2014-01-02 Thank you very much. I was going to understand what happen with the matrix and did not understand how to do. But this is easy . So I changed the code and now I have two results: test-rgb.dat with the old calculation test-yuv.dat with the new calculation I think that the new calculation did it not better than the old one if I compare the results. Does anybody has an idea how to improve the automatic conversion process? I am looking forward to your idea Re: color matching for pattern - Rolf Osterthun - 2014-01-02 Hey Michael, would you share the original image with me. I would like to test something... Thanks Rolf Re: color matching for pattern - Philippe Hurbain - 2014-01-02 It's LDD 88174 pattern... Re: color matching for pattern - Tim Gould - 2014-01-02 Hi Mike, Those colours might be closest in both spaces. All these algorithms can do is choose the _best_ neighbour from a list according to their metric. What exactly is the proccess you follow in choosing your pallette? Are you trying to determine the best set of colours? Because that is a different problem again. The more info I get, the more I can try to help Tim Re: color matching for pattern - Travis Cobbs - 2014-01-02 It might be possible to make your quantizer antialiasing-resistant, but I'm not sure how well it will work. The basic idea would be like so:
Like I say, I'm not sure how well it will work, but it seems like it should get rid of the problem where black lines get blue and yellow pixels due to the original antialiasing. Re: color matching for pattern - Michael Heidemann - 2014-01-03 I like to follow the following procedure: 1) select picture 2) mark in the picture the colors that should appear in the output 3) detect the regions with different colors based on step 2 (this is what we are talking about) 4) create LDraw file There are more steps behind, but this should be the steps the user should make. Rolf has already made a good region detection on the picture if not choosing black but a grey. So he adjusted the treshhold value. But this can be done only manually by the user. I fear that the attempt from Travis will also do not give better results if no further user action is taken. But I like to keep the user action to a minimum, so everybody should be able to make a LDraw file from a picture If you have more questions please ask. Re: color matching for pattern - Tim Gould - 2014-01-03 The problem in your example is that the grey anti-aliased pixels are closer in brightness to the blue than it is to the black. So what about offering the user the chance to increase the size of selected regions? Increase the various black selected zone by half a pixel and all your problems will disappear. Tim Re: color matching for pattern - Michael Heidemann - 2014-01-03 Code: Increase the various black selected zone by half a pixel and all your problems will disappear. In the first step I (the user) decide which colors should appear in the result. To these colors all pixels are mapped each. With this new colored picture the application can decide what regions are the same color. So the regions are detected _after_ color reducing. Any more thoughts? Re: color matching for pattern - Tim Gould - 2014-01-03 I misunderstood your process. But after should work too. Offer a chance to the user to increase by one pixel the size of a given colour region (like magic wand in photoshop or GIMP). So the user points his cursor onto a colour in the pattern and then selects "grow by one pixel". Then the connected region in that colour is simple increased by one. But really it is all these annoying small issues that made me drop my old vector sticker maker program. One day I would like time to try again. Tim Re: color matching for pattern - Michael Heidemann - 2014-01-03 Thanks for your quick answer. I have to think about your suggestion how to apply to my code and we will see the results. It seems that anybody has tried to fill this gap in applications Now we should go with our global power and knowlage and solve these problems Re: color matching for pattern - Tim Gould - 2014-01-03 Well if you can get this antialiasing issue fixed I will try again to deal with vectorisation. Your current output is much easier to deal with. Tim |