I have made a small example showing the problem: http://bl.ocks.org/nvcleemp/df035fc9c14f9955d4f0
When you click any of the two links, then you see a small animation which changes the background colour. This animation always starts from black, while I want it to start at the current colour. This is just a small example, in the real problem there are many more links that have to change colour, and I don't 'know' which is the correct starting colour. (I can always look it up, but I cannot hard-code it into the function)
The safest way to have a transition start from a well-known state is to set that state yourself. In your case, set the background colour at the beginning:
d3.select("#test1").style("background", notSelectedColor);
d3.select("#test2").style("background", notSelectedColor);
Complete demo here.
Related
I am trying to create an app in which I have a single cloth picture (a women ethnic top, with obviously shadow effect to make it look real) and I want the user to click on a color tab on the right side, so that the color of the top changes, but the shadow effect should remain the same.
I am using libgdx for this. I have created a texture from the input top image and used linear filter to smoothen it. the original top looks like:
The new cloth that I want to place on the top is:
Initially I converted every pixel of the shirt from rgb space to hsv space. I tried 4 methods to achieve the above problem:
I used hue,saturation from new cloth, and brightness(I have to take shadows, they have low brightness) from the shirt. The problem here is the fabric color becomes light due to the low brightness in the top (brightness comes from the top). It produces the below image:
I used hue,saturation from the new cloth, and set a cut off for the brightness from the top. 70% is the cut off. The problem here is that the shadows are not clear as the fabric is dark:
I used z-score to calculate brightness at each pixel. The z score for brightness at every pixel in the blouse is used to adjust the brightness in the cloth. z score for every pixel is made the same, and the brightness for the fabric is calculates. This image is also not looking much acceptable:
I need a help on what approach should I use to achieve the above scenario. Am I on the right track, or I am doing something completely wrong. May be I should remove the outer color to see if the top looks realistic (since the background and top color become same, is this the reason for an unrealistic result?
First of all I'm not really sure if LibGDX is proper and best tool for the things you want to implement. For me it rather looks like a job for a library connected with image processing like OpenCV mobile for example.
The truth is that I haven't used it yet (although I have some experience with OpenCV itself) and the fast googleing didin't return any "official" tutorial how to integrate this with libGDX (although I'm pretty sure it is possible).
Anyway - if you want to use LibGDX to operate on colour like this you have a SpriteBatch'es method
void setColor(Color tint)
that you can use for colorizing the SpriteBatch you are using for rendering things.
Due to default generated project the effect is as you can see:
without tint:
batch.begin();
batch.draw(img, 0, 0);
batch.end();
tint applied:
batch.begin();
batch.setColor(Color.GREEN);
batch.draw(img, 0, 0);
batch.end();
Please also notice that tinting image is naive that means that it will colorize also background so you need to cut the image from it's background and save it in .PNG format.
Take a look at this example:
I need to convert an image to greyscale except for a single color. For example, if there is some red in the image (like a red bus), this will remain in color, but the rest of the image will remain in black & white.
I think I should be able to do a rudimentary job of this by going over each pixel individually, such as here: http://brandontreb.com/image-manipulation-retrieving-and-updating-pixel-values-for-a-uiimage . I am assuming I would just leave certain pixels alone if their red component was above a certain amount, and green/blue was below a certain amount. Otherwise, set the pixel to grayscale. Is this a good approach?
I'm more interested in whether or not it is possible to do to the live camera input, such as with a Core Image filter, or using GPUImage, but I haven't been able to find any suitable filters. Any suggestions?
Update:
This seems to be possible using GPUImage with a GPUImageLookupFilter, as per: https://stackoverflow.com/a/19340583/334982
I've created a lookup.png file in Photoshop, by dropping the Saturation for all colours except red to 0. This works ok, but it doesn't seem to grey out all colours. For example, my skin still looks fairly skin coloured, and my brown table is still fairly brown.
I'm using jqPlot to render a graph with zooming enabled.
For example:
http://www.jqplot.com/tests/zooming.php
In the example above, when you make a selection on the graph, the graph canvas is painted in grey (apart from the selection). Does anyone know how to customise this colour?
I've been unable to find which jqPlot CSS option to tweak in jquery.jqplot.css.
I am afraid that no css is involved in this particular process of painting. Though there is one class which can point you in the right direction. My suspect is the jqplot-zoom-canvas class. Though I think that the painting is defaulted to grey.
Thus, I see only two options:
Changing the painting directly in the jqplot script.
Or on painting of zoom selection start change the colour of the jqplot-zoom-canvas then change it back to default on painting zoom stop. But I do not know if there are hooks for these sort of events. Therefore, you might actually be left with only the option no. 1.
I have 3 nice and puffy clouds I made in Photoshop, all the same size, now I would like to animate them so they appear like they were moving in the background. I want this animation to be the base background in all my scenes (menu,settings, score, game).
I'm using cocos2d, I have setup the menus and the buttons so the work but how do I accomplish this?
I was thinking to add this as a layer, any other suggestions?
Can anyone show me how some code how to make this please?
David H
A simple way to do it is with sine and cosine. Have slighly different parameters (period and amplitude) to ensure that the user doesn't realise (as easily) that they are programmatically animated.
You may also want to play with animating the opacity value. I'm not sure if layers have those, otherwise you'll have to add the clouds to separate nodes or images and applying it to them.
It's hard to be more specific without knowing what the images look like.
The simplest way to animate anything is to add the sprite to the scene, set the position and call something like...
[myClouds runAction:[CCMoveBy actionWithDuration:10 position:CGPointMake(200, 0)]];
This will slide the sprite 200px to the right over 10 seconds. As Srekel suggested, you can play around with some trig functions to get a more natural feel and motion paths, but you'll have to schedule a selector and iteratively reposition the elements.
The more difficult part of your questions is about getting the animation in the background of all scenes. Keep in mind that when you switch scenes, you're unloading one node hierarchy and loading a new one. The background cannot be shared. You CAN, however, duplicate the sprites and animation in all scenes, but when you transition between them there will be a jump.
Using images of articles of clothing taken against a consistent background, I would like to make all pixels in the image transparent except for the clothing. What is the best way to go about this? I have researched the algorithms that are common for this and the open source library opencv. Aside from rolling my own or using opencv is there an easy way to do this? I am open to any language or platform.
Thanks
If your background is consistend in an image but inconsistent across images it could get tricky, but here is what I would do:
Separate the image into some intensity/colour form such as YUV or Lab.
Make a histogram over the colour part. Find the most occuring colour, this is (most likely) your background (update) maybe a better trick here would be to find the most occuring colour of all pixels within one or two pixels from the edge of the image.
Starting from the eddges of the image, set all pixels that have that colour and are connected to the edge through pixels of that colour to transparent.
The edge of the piece of clothing is now going to look a bit ugly because it consist of pixels that gain their colour from both the background and the piece of clothing. To combat this you need to do a bit more work:
Find the edge of the piece of clothing through some edge detection mechanism.
Replace the colour of the edge pixels with a blend of the colour just "inside" the edge pixel (i.e. the colour of the clothing in that region) and transparent (if your output image format supports that).
If you want to get really fancy, you increase the transparency depending on how much "like" the background colour the colour of that pixel is.
Basically, find the color of the background and subtract it, but I guess you knew this. It's a little tricky to do this all automatically, but it seems possible.
First, take a look at blob detection with OpenCV and see if this is basically done for you.
To do it yourself:
find the background: There are several options. Probably easiest is to histogram the image, and the large number of pixels with similar values are the background, and if there are two large collections, the background will be the one with a big hole in the middle. Another approach is to take a band around the perimeter as the background color, but this seems inferior as, for example, reflection from a flash could dramatically brighten more centrally located background pixels.
remove the background: a first take at this would be to threshold the image based on the background color, and then run the "open" or "close" algorithms on this, and then use this as a mask to select your clothing article. (The point of open/close is to not remove small background colored items on the clothing, like black buttons on a white blouse, or, say, bright reflections on black clothing.)
OpenCV is a good tool for this.
The trickiest part of this will probably be at the shadow around the object (e.g. a black jacket on a white background will have a continuous gray shadow at some of the edges and where to make this cut?), but if you get this far, post another question.
if you know the exact color intensity of the background and it will never change and the articles of clothing will never coincide with this color, then this is a simple application of background subtraction, that is everything that is not a particular color intensity is considered an "on" pixel, one of interest. You can then use connected component labeling (http://en.wikipedia.org/wiki/Connected_Component_Labeling) to figure out seperate groupings of objects.
for a color image, with the same background on every pictures:
convert your image to HSV or HSL
determine the Hue value of the background (+/-10): do this step once, using photoshop for example, then use the same value on all your pictures.
perform a color threshold: on the hue channel exclude the hue of the background ([0,hue[ + ]hue, 255] typically), for all other channels include the whole value range (0 to 255 typically). this will select pixels which are NOT the background.
perform a "fill holes" operation (normally found along blob analysis or labelling functions) to complete the part of the clothes which may have been of the same color than the background.
now you have an image which is a "mask" of the clothes: non-zero pixels represents the clothes, 0 pixels represents the background.
this step of the processing depends on how you want to make pixels transparent: typically, if you save your image as PNG with an alpha (transparency) channel, use a logical AND (also called "masking") operation between the alpha channel of the original image and the mask build in the previous step.
voilĂ , the background disappeared, save the resulting image.