[Image Processing]Thresholding Not Ignoring the transparent pixels - image

Currently I am trying to crop the face along with hairs by the help of image segmentation methods, and then I have set all the non color pixels to be transparent, Then I am trying to apply Binary Threshold technique and Adaptive Threshold. But I am getting non-desirable results. Unfortunately the OpenCV methods are not ignoring the transparent pixels, and in documentation it is not defined how to handle this case, Any experienced help is appreciated (However I can replace the transparent pixels by a color value, provided I get the desired results)
Image 1.png(original Image with transparent background)
Image2.png(Image after applying simple binary threshold)
Image3.png(Image after adaptive threshold)
Clearly some image distortion/Noise is seen in the transparent areas of the image ?

And I was able to solve this issue , I am posting this answer to help other fellow people for the educational purposes, and due to limited clarification about this thing, So the hack is to change the background color to be white(it worked in my case but you can surely choose some other background color), So now I colored all the pixels with alpha value 0 as while colored opaque pixels and then applied the required operations, And the outputs were as per expectation:
Then applied some more image processing features to create this image out of this:

Related

HTML5 canvas - make a mono mask efficiently without antialiasing

I am using pixel colour inspection to detect collisions. I know there are other ways to achieve this but this is my use case.
I draw a shape cloned from the main canvas on to a second canvas switching the fill and stroke colours to pur black. I then use getImageData() to get an array of pixel colours and inspect them - if I see black I have a collision with something.
However, some pixels are shades of grey because the second canvas is applying antialiasing to the shape. I want only black or transparent pixels.
How can I get the second canvas to be composed of either transparent or black only?
I have achieved this long in the past with Windows GDI via compositing/xor combinations etc. However, GDI did not always apply antialiasing. I guess the answer lies in globalCompositeOperation or filter but I cannot see what settings/filters or sequence to apply.
I appreciate I have not provided sample code but I am hoping that someone can throw me a bone and I'll work up a snippet here which might become a standard cut & paste for posterity from that.

Removing semi-transparent overlay on flattened image

A solution to this problem seems to not exist but I find it hard to believe it is not possible.
Imagine you have an image with a semi-transparent overlay (color=black, transparency=50%), whether over the whole image or just a portion, doesn't matter. How could one convert the pixels underneath to their original color, in essence removing the black overlay.
Just like a simple algebra equation we should be able to rearrange the variables to solve for the "original pixels" under the overlay. Something along the lines of -
original pixels * semi-transparent overlay = new pixelsoriginal pixels = semi-transparent overlay / new pixels
Obviously such an equation over simplifies the problem but I think that gets my point across. Since we know the color and percent transparency, why couldn't we "retrieve" the colors of the underlying pixels?
EDIT: Mark Ransom in the comments is correct, if you know the transparency is 50% then simply multiplying by 2 gets you to the original color. Any recommendations on how to apply this to a whole region in Photoshop or GIMP? Certainly doing it pixel by pixel is out of the question.
Thank you!
The "divide" layer mode will do what you want. In the case of semi-transparent black, use a gray with the value equal to the opacity value of the overlayed layer.

UIImage - highlight single color only

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.

Replace all solid colors in a UIImage

I'm trying to perform image recognition via a SIFT algorithm using solid shapes.
To improve the performance, I would like to take the image (captured from an iOS camera), make all non-light colors a dark red and make the remaining pixels transparent.
An example of a before and after of what I'm trying to achieve is attached in the images on this question.
Assumption: the images are always solid-black shapes and printed on plain white paper
Can someone please help me with this or point me in the right direction?
As provided in this code, you can simply iterate over the pixel data and compare each color of the pixel with the value you want to filter. But before you should maybe apply some filters for better results.

Edge Detection and transparency

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.

Resources