7/29/2023 0 Comments Lego image converterSet.type(lpm, 1:(areas*colors), "binary") Lpm <- make.lp(colors + areas, areas*colors) I teach my students how to solve models of that class with 3 variables and 5 restrictions by hand (a fun activity, I know) and it takes quite a while □ areas <- max(is_area) I was concerned that the optimization of such a large model would take too long and require too much memory. Taken together with the 15 colors provided by the ‘The Beatles’ set this means that you have 30,000+ variables with 2,000 + restrictions. The resulting linear programming model can become relatively large as the 48*48 images have a lot of areas at least when you have an input image with a large color depth (more than 2,000 in most cases). The restrictions are the tile set limitations and the requirement that each color area must be transformed to exactly one mosaic color. The objective function is to choose variables so that the overall cost of the color deviation is minimized. The cost is defined by the color distance (yet another topic where Wikipedia is very helpful) of the original color and the selected color multiplied with the size of the area. The pointer to the Hungarian Method helped me to understand that my problem can be described as a linear programming problem with each area/potential color pair being a variable that can take a binary value. After thinking and reading about the problem a little bit, I found this discussion on (again) Stack Exchange. But here my day job as an applied economist came in handy. After implementing a first ‘greedy’ match, my results looked very similar. Given my experiences with the web-based conversion tools available (I am entirely sure that I overlooked some) I was not optimistic. With the second bullet point of my “specification list” knocked off, I moved on to focus on the automated conversion. I thought about ways to implement this efficiently in shiny and then I ran across this wonderful shiny module offered by Garrick Aden-Bule. This looked like another road block, given my time budget for my toy project was only a few days and mostly the early hours where the rest of my family was sound asleep. Second, after playing with the editing interface, I quickly noticed that a proper undo feature is really important for it to become usable. Another feature of this, the changing text color depending on the background, is based on this Stack Overflow snippet pick_text_color_for_bground 0.5, "#000000", "#ffffff") I am a CSS noob so this one would have been very hard for me without the help of this Stack Overflow discussion. If (x 1) identify_area(area, x, y - 1, color) If (is.null(color)) color 1) identify_area(area, x - 1, y, color) # as well as an img raster containing the actual data # needs to be defined prior to calling identify_area() # Writes to a matrix is_area in a higher environment so this # This identifies areas with the same color within a 48*48 bitmap Flood-fill is one of these neat examples for the power of recursive algorithms and with the help of Wikipedia implementing it was almost to easy. 1Īfter selection has been taken care off, I wanted to implement flood-fill selection so that users can easily select areas that they want to convert. This often goes unnoticed but I believe that this platform has developed to one of the most important knowledge resources for software development and even regularly informs academic research. I reference this here not only to give its participants the credit that they deserve but too highlight the maaaanny times that I benefited from the Stack Exchange universe. I quickly found this discussion on Stack Overflow that helped me to get the idea. How does one select pixels from the image for modification? Time to google. LEGO Mosaics have been around for a while and there is the wonderful before, so: Why not? Time to produce a first screen shot.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |