Replace all solid colors in a UIImage - image

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.

Related

Extracting parts of an image based on a grid mask

I have been checking some jigsaw puzzle games around and I have noticed some of them use a grid image to extract pieces from an image. The image that represent the grid of pieces to extract is an image with white lines (the contour of pieces) and all the rest is just transparent. I have been struggling looking for ways to use this image to extract the pieces for my own game but haven't figured out how to do it.
Could anyone give any tip about how to use this image to extract the pieces?
An example of the image can be seen here. Take into account I have painted the white lines with a blue color to make it visible here at stack overflow:
P.D. Thinking a bit more about it, the only solution I found but I think it is too slow though is use something like a flood fill algorithm to extract the pixels and build the image set using piece center as starting points. This method could be used for any set of pieces with a regular width/height.
Cheers.

[Image Processing]Thresholding Not Ignoring the transparent pixels

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:

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.

2d texture to a 3d item?

I want to do what they do in Minecraft and that is take a 2d item and make a it 3d.
This:
to this:
Anyone have idea how I would do this without making a model in a seperate program
Well, if you have proper images with a nice contrast to the background, you could try to read the image's pixel value and contrast and try to find the outline of those images. As a next step, you would use Three.Shape or Three.Path and trace the outline with LineTo. Afterwards, you use an ExtrudeGeometry and extrude the shape into a 3d-object.
The main problem is finding the outline, i guess. This would only work with proper images and depending on the quality you want to achieve, you will have to implement the proper algorithms, see edge detection filters maybe.
Or being very simplistic, read the pixel values, if they are white or close to white, ignore them and if they are not, Draw another line.... something like that...

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