Color picker by a color tree - algorithm

Sorry for the bad title I don't really know how could I write it better. I want to create a colorpicker that's not very typical. There is the version where you can select the three vectors of HSB. It would be close to it but not at all. The main problem is why I don't use the usual colorpickers is that I have a very specific space to do it. I have 35 free objects that could be colored (these are filled circles with a black border) and not more. But I can place each object wherever I want. So how I imagine there would be a circle of 12-18 objects that are constats they would represent the HUE than when I select one the rest of the objects would be in the HUE circle and they would form a square. And why I call it tree: because you could select a color from the main circle than you get colors from that branch than you click on one of the colors in the got colors than you get colors from that color (but the clicked color is always part of the "zoomed" colors the best how you can imagine this like there is the HSB color space and in the first two clicks you select the HUE than you just zoom in the HSB color space than there is the two dimensional 101*101 S and B square and we zoom on the color. I really hope that you can understand me if not ask anything. And thank you for reading this long text.
Something like this:

The first, must know what is equation of HSB Color. The Algorithm to find this is in this with name HSV.
If you found, You can fill each color with choosen formula with hue you choosen and full saturation.
Add listener of click for that circle.
In listener, update the cicle inside with your choosen saturation and brighness. For example first row is sqaturation and brightness is column. Then in row 1 is no saturation, row 2 is half saturated(50) and row 3 is full saturated ones. The column 1 is the brightmost one(100) the 2 is half(50) and 3 is no brightness (0), for example.
Aclually it is not a tree, but a alternative approach for standard approach because it's more like that than tree.

Related

Adding controller buttons to prompt text?

I want to make a controller button prompt in my game where it says 'Press X to Join', but I want the X to be an actual graphic of the 'X' button, like how it is in many games. How would I go about doing that? Right now I'm just putting a big space in my prompt text and putting a UI Image of the button in it, but I want to know if there's a better way about it.
For the sake of scaling to different resolution sizes, you would wanna scale the anchors of the UI elements correctly and have an appropriate parent-child relation tree in Unity's hierarchy.
The red box is the hierarchy.
The 2 green boxes shows ways of scaling the anchors.
The orange box shows the end result of it.
Anchors in combination with their relative position, allows Unity's UI elements to scale up and down according to screen size.
So for example if you say that an anchor is at 0.25x, that would be that its anchored at 25% of for example the x axis. Same goes if you set it for the y axis, just the vertical instead of horizontal anchoring.
You can use the anchors to adjust a minimum and a maximum anchor which the elements may float within, they may have the same value as well, then it's a fixed anchor point.
To clarify, I suggest that you use a panel to hold 2 text elements and the image with the X, each text element being on the left and right side of the X instead of having spacing inside the UI text elements. To keep correct spacing you then must use anchor points. This way your spacing stays correct despite changing screen and resolution sizes.
Please note that the "left", "top", "right" and "bottom" values are then relative to the anchor points. So if you move "left" 5 pixels, those 5 pixels will be out from the relative anchor point.
Here's the values I used:
My left text is at 0.25x, right text is at 0.8x, image is at 0.5x.
The panel holding the 3 is at 0.2 minimum x to 0.8 max x, same goes for y axis.
The largest parent panel is stretched to max fit in the canvas.

How to check whether a svg circle inside the svg path

There are many ways to check is point inside path, but i haven't found any algorhitm which can check if the circle(whole object, not center point) is inside svg path.
If you're wondering why I need this algorithm - i want to fill space with circles with different radii (http://bl.ocks.org/mbostock/1893974), and those circles that enters the shape i want to paint in another color. As a result, we get the test image for color-blind people, like Ishihara's pictures.
The expected result like on that picture.
This a collition detection algorithm or intersection.
Step 1
Fill with cirlcles you base shape
Step 2
Create the main shape
Step 3
Detect interserct and color the shape behind. And hide the main shape
Pros: You can add dynamically shapes, animate or change it on the fly.
For an implementation look here

How to cut extra background in image?

Say I have an image that looks like this:
I fail to see what approach I could take in order to modify the picture so that all the background color surrounding the image is gone. So, a potential result would be this:
As you can see the white background has been cut out and now is about 2 pixels from the actual shoes.
I don't have just shoes, but I am looking for an algorithm that would let me do that. I am using Ruby and Minimagick, but I guess that first step would be to figure it out the algorithm that I could use.
EDIT: The background is not necessary white.
If I understand you right, this sounds like a simple task that doesn't need any fancy algorithms.
Find the background color of the image. One simple way to do that would be to just take the color of the pixel in, say, the top left corner. There are fancier ways you could use, but this will work for your example image.
Find the leftmost and rightmost columns containing a pixel of some color other than the background. Those columns will be the leftmost and rightmost columns of your cropped image.
Find the topmost and bottommost rows containing a pixel of some color other than the background. Those rows will be the topmost and bottommost rows of your cropped image.
Crop the image to the dimensions found above. If you want, you can adjust the dimensions to leave a border of any size you want around the image.
Use s-t minimal graph cuts algorithm from standard image processing library

Any ideas on how to remove small abandoned pixel in a png using OpenCV or other algorithm?

I got a png image like this:
The blue color is represent transparent. And all the circle is a pixel group. So, I would like to find the biggest one, and remove all the small pixel, which is not group with the biggest one. In this example, the biggest one is red colour circle, and I will retain it. But the green and yellow are to small, so I will remove them. After that, I will have something like this:
Any ideas? Thanks.
If you consider only the size of objects, use the following algorithm: labellize the connex components of the mask image of the objects (all object pixels are white, transparent ones are black). Then compute the areas of the connex components, and filter them. At this step, you have a label map and a list of authorized labels. You can read the label map and overwrite the mask image with setting every pixel to white if it has an authorized label.
OpenCV does not seem to have a labelling function, but cvFloodFill can do the same thing with several calls: for each unlabeled white pixel, call FloodFill with this pixel as marker. Then you can store the result of this step in an array (of the size of the image) by assigning each newly assigned pixel with its label. Repeat this as long as you have unlabellized pixels.
Else you can recode the connex component function for binary images, this algorithm is well known and easy to implement (maybe start with Matlab's bwlabel).
The handiest way to filter objects if you have an a priori knowledge of their size is to use morphological operators. In your case, with opencv, once you've loaded your image (OpenCV supports PNG), you have to do an "openning", that is an erosion followed by a dilation.
The small objects (smaller than the size of the structuring element you chose) will disappear with erosion, while the bigger will remain and be restored with the dilation.
(reference here, cv::morphologyEx).
The shape of the big object might be altered. If you're only doing detection, it is harmless, but if you want your object to avoid transformation you'll need to apply a "top hat" transform.

Selective Color of image

I have more then 1 week reading about selective color change of an image. It meand selcting a color from a color picker and then select a part of image in which I want to change the color and apply the changing of color form original color to color of color picker.
E.g. if I select a blue color in color picker and I also select a red part in the image I should be able to change red color to blue color in all the image.
Another example. If I have an image with red apples and oranges and if I select an apple on the image and a blue color in the color picket, then all apples should be changing the color from red to blue.
I have some ideas but of course I need something more concrete on how to do this
Thank you for reading
As a starting point, consider clustering the colors of your image. If you don't know how many clusters you want, then you will need methods to determine whether to merge or not two given clusters. For the moment, let us suppose that we know that number. For example, given the following image at left, I mapped its colors to 3 clusters, which have the mean colors as shown in the middle, and representing each cluster by its mean color gives the figure at right.
With the output at right, now what you need is a method to replace colors. Suppose the user clicks (a single point) somewhere in your image, then you know the positions in the original image that you will need to modify. For the next image, the user (me) clicked on a point that is contained by the "orange" cluster. Then he clicked on some blue hue. From that, you make a mask representing the points in the "orange" cluster and play with that. I considered a simple gaussian filter followed by a flat dilation 3x5. Then you replace the hues in the original image according to the produced mask (after the low pass filtering, the values on it are also considered as a alpha value for compositing the images).
Not perfect at all, but you could have a better clustering than me and also a much-less-primitive color replacement method. I intentionally skipped the details about clustering method, color space, and others, because I used only basic k-means on RGB without any pre-processing of the input. So you can consider the results above as a baseline for anything else you can do.
Given the image, a selected color, and a target new color - you can't do much that isn't ugly. You also need a range, some amount of variation in color, so you can say one pixel's color is "close enough" while another is clearly "different".
First step of processing: You create a mask image, which is grayscale and varying from 0.0 to 1.0 (or from zero to some maximum value we'll treat as 1.0), and the same size as the input image. For each input pixel, test if its color is sufficiently near the selected color. If it's "the same" or "close enough" put 1.0 in the mask. If it's different, put 0.0. If is sorta borderline, put an in-between value. Exactly how to do this depends on the details of the image.
This might work best in LAB space, and testing for sameness according to the angle of the A,B coordinates relative to their origin.
Once you have the mask, put it aside. Now color-transform the whole image. This might be best done in HSV space. Don't touch the V channel. Add a constant to S, modulo 360deg (or mod 256, if S is stored as bytes) and multiply S by a constant chosen so that the coordinates in HSV corresponding to the selected color is moved to the HSV coordinates for the target color. Convert the transformed S and H, with the unchanged L, back to RGB.
Finally, use the mask to blend the original image with the color-transformed one. Apply this to each channel - red, green, blue:
output = (1-mask)*original + mask*transformed
If you're doing it all in byte arrays, 0 is 0.0 and 255 is 1.0, and be careful of overflow and signed/unsigned problems.

Resources