C# converting png image to list of points - c#

I have a .png image, i want to get the points that the shape is made of.
Example:
I know that i won't get a perfect output but anything would be good..
How should I start?
I would need to get a list of points out of my image.

Very simple. Replace an NON white pixels by black. Then loop in each black pixel and turn them white if not adjacent to at least 1 white pixel.

Related

Fill png image with certain number of points

I'm working to a software that need a strange feature. I choose a png image like image attached and I need to place uniformly a certain number of points on black surface. I started with loop each pixel and change it's color to black, only for design, but now I need to think an algorithm to fill it with points (like 200 points (pixels with red color). You have a idea how to do this ?
Now in my mind is to count black pixels, then do something like this blackPixelsPerPoint = blackPixels / numberOfPoints. After this I now i need to have a red point every blackPixelsPerPoint.
The result need to be something like N letter
The points need to have almost same space between them and fill all the black surface if is possible (depend by number of points).

How to get content of an image from a pattern?

I need to get the shape of the person given a pattern that came from the absolute difference of the two pictures, then converting it to bitmap to remove all the black pixels. How can I get the person's original body given these images
Original image, Absolute difference image, Removed black pixel(Bitmap)
It's not very clear to me what you are trying to do, but whatever it is, I think it is a 2-step process that will go something like this...
First, make a mask image that is black and white. Make it white where you want the original image to show through and black where you don't. Not sure which image you want to start from, but let's take the second one with black, white, cyan and blue in it. Let's make it pure black and white. You may choose a different method but I will just threshold:
convert 2.jpg -threshold 50% mask.png
Now, second step. Apply the mask as the opacity/alpha channel for the first, colour, original image:
convert 1.jpg mask.png -compose copy-opacity -composite result.png
As the face of the lady is missing, there is some issue with the way you are generating the mask. I guess the face is too similar to the background in tonality. Consider having a look at Morphology to "close the holes", along these lines:
convert 2.jpg -threshold 50% mask.png
convert outline.png -morphology Close Disk:12 mask.png
convert 1.jpg mask.png -compose copy-opacity -composite result.png

How can I set an image to have a transparent background in C# without using Bitmap.MakeTransparent()?

I want to set an image to have a transparent background, but I do not want to replace all pixels of a specific colour with transparency.
To be more specific, the image is a thumbnail image for a folder, obtained via IShellItemImageFactory.GetImage. This gives me a Bitmap, as displayed in Windows Explorer thumbnail view, but the background is solid white.
I can use Bitmap.MakeTransparent on it, and that will work in most cases, but in any cases where the thumbnail image contains white itself (for example, a folder that contains images, which include white colours).
Incidently, this is the first time in over 10 years as a developer that, after googling my question, I have not found an answer anywhere, and I've actually had to ask it myself. (I think that means I just levelled up! Yippee, I am now a level 2 developer...)
Use flood-fill algorithm to fill pixels of the same color from the OUTSIDE as you need it. It is something similar to magic wand in photoshop.
http://en.wikipedia.org/wiki/Flood_fill
What I would do is flood-fill with some obscure color (Magenta always does it for me), then replace that color with transparent (I don't know if flood filling with transparent pixels is feasible).
So what you're getting from IShellItemImageFactory.GetImage is a composite image that contains the original image on a white background? I suspect the white background is there if the image doesn't have the same aspect ratio as the thumbnail size. For example, if you ask for a 96x96 thumbnail of a 640x480 image, there's going to be some white space at top and bottom.
If that's the case, you have a problem. You can't differentiate between white pixels that are contained in the image, and white pixels that are added by GetImage.
There are a few things you could do. You could load the image and resize it yourself. That's probably the easiest. You'd want to maintain your own thumbnail cache then.
Or you could examine the image returned by GetImage to look for white space on the sides. Basically, if every pixel on a row (or column) is white, then make that row (or column) transparent. It's a little more complicated than that (the NBA logo, for example). But that's essentially what you'd want to do.

How to detect if image is being displayed as negative (inverted)?

Is it possible to detect if an image is being displayed as a "Negative Image" in C#? In other words the colors are inverted?
If you don't have the original image to compare (and then what you are trying to do is detecting if an image is the negative of another one), then you can only try to guess that it is some kind of negative image, but you cannot be 100% sure about it.
The negative image is simply the image where each pixel colour is:
Red = 255 - originalRed
Green = 255 - originalGreen
Blue = 255 - originalBlue
If you know what the colour of any particular pixel should be you can test that to see if it matches or is inverted.
Other than that I can't think of a foolproof way that would work for any image. You could look at colour distributions but that will depend on the image.
You would need to do some statistical analysis on the properties of inverted and non-inverted images to get some criteria to check. For example, perhaps there are colors that are uncommon in normal images but common in inverted ones. Maybe the center of a normal image is usually brighter than the edges, or the top is brighter than the bottom.
No method is going to be 100% accurate, as any image is ultimately just as valid as any other.

Compare text within two images, but regardless of color

I want to compare two images.
On both images you can see a digit. For example: (img1: "5" img2: "5") img1 is a pure black digit. But img2 could be in various colors. The background is white. It doesn't matter what color is on img2, if there is a "5", it has to be matched.
How do I compare these images? It has to be a fast method.
Any clues?
If you know the background is always white, you could process the two images and whenever a pixel is not white, set it's color to black - essentially converting both images into black & white bitmaps.
Then you could compare the bitmaps. I'm assuming you have that part already covered. Otherwise, if the two images are supposed to be exact matches then you would go and compare each pixel to the other image for an exact match. If a pixel doesn't match.. they are not the same. But this is very naive.. much better image recognition methods exist.

Categories