Removing black areas from a scanned image with C# - c#

I have a bunch of images, that look like .
After processing, I want them to be like .
I know that I can easily make those black areas white using the Flood Fill algorithm. But first of all I need to make sure that the black area is not part of the text. How can I do that? Those areas are huge, comparing to letters. So maybe I can just find out the size of each black area, and make the areas which are bigger than n white?

That's all about machinevision.
You could write your own code for something like "Connected-Component-Labeling"
This is just one possible approach.
Therefore you could start at the top left corner and gather all pixel that have almost the same grey value. save the coordinates and fill this area if the array contains more pixel than a certain threshold.
But i think you ll have some probs with the black "line" in the middle.

Related

Split an image up into quadrants or splice image into multiple?

So I have one image that on paper they were drawing lines/circles on particular areas of the image that they had designated certain sides as area 1-4, then 5-6 in the center and then a few specific spots as area 7. They wanted to make this digital. So I put the image on a win form, made it so they can create lines and circles (eventually I'll have it so the lines are measured and stored in an array) However along with storing that I need to store what number area the line/circle was created in for tracking purpose so they can look back later to see where the majority of, in this case flaws, are being circled on the image. (The image represents a real machine part). So right now I'm stuck trying to figure out how to designate certain areas of this image as area 1-4, 5,6 (and multiple 7's).
Is it better to split each area up into its own photo and piece them together like a puzzle? Or is there a better way in code to do this leaving 1 image to work with?

Identify groups of similar-coloured pixels

I am writing some software that periodically checks a camera image to identify whether an object has been introduced to the viewed scene. I am using ImageMagick in my WinForms software to compare two images to create a third. In the third image, a pixel is white if the first two images had a similar-coloured pixel, and black if they were different. So if the user sees a group of black pixels, they will know something has been placed in the scene that wasn't there previously, as seen here:
The user will not be seeing this image, so I would like my software to identify this for me. I don't need anything too complex from this analysis - just a Boolean for whether something was changed in the scene.
In my mind, there are two approaches to analysing this; counting the number of black pixels in the image, or I could write some algorithm to identify patches of black. My question is about the second approach, since it feels like the more correct approach. The image is a bit too noisy (you can see false positives on straight edges) for me to feel entirely comfortable with counting.
To identify a group, I have considered using some for loops to look at the colours of pixels surrounding every pixel but this seems like it would take forever. My processing time can't take more than a few seconds so I need to be wary of this. Are there cleaner or more-efficient ways to identify groups of similarly-coloured pixels? Or will I need to run loops and be as efficient as possible?
Threshold the image such that black pixels will have value 1 non black will have zero.
Use connected component labeling to find all the groups of connected black pixels. http://www.imagemagick.org/script/connected-components.php
Filter out the components that are too small or doesn't have the correct shape(for example you can have a long line on the sides so they have a lot of black pixels but you are not expecting to see a long line as a valid group of black pixels)
At this point I assume you have a sense of the scale of the objects that you are interested in capturing. For example, if you did have an entirely non-black screen (let's ignore noise for the purpose of this discussion), except you have a black pixel object that is only roughly 10 pixels in diameter. This seems to be frightfully small, and not enough information to be useful.
Once you have determined what is the minimum size of black mass you are willing to accept, I would then go about querying a staggered matrix.
i.e., a pattern like:
Use a little math to determine what acceptable noise is.
Once you have positive results, (pixels = black), investigate in those sectors.

Emgu CV - ignore a color while matching template

I'm using Image class and it's MatchTemplate method in Emgu CV to detect pattern in pictures. So, my pictures are black-white (with 256 gray variants) and I have to search for white templates, but how do I store them? If I'm using .png with only 2 colors: white for pattern and black for background - then MatchTemplate method considers the background part of template (and that's ruining the results). What color I have to use for background in patterns?
UPD: Images added.
Pattern (only white triangle needed):
Image example (a simple one):
Detection (white square is what I get, red one - what I need):
Please read this:
http://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate
You obviously don't know how matchTemplate works.
You cannot simply pick one colour for the background to be ignored. The algorithm always calculates some difference measure between template and some image region. Unless image and template background are the same you will always have an influence.
If you want to "ignore" the background you would have to replace the background by the image region for every iteration so the difference of backgrounds becomes 0 or at least the same for every pixel. This doesn't sound very efficient.
Provide input images and template examples. There is most likely a better solution for your problem.
You should probably modify your template image by removing the four black sides, which leaves only the white triangle and the black one. That should help you get your desired result.

From picture units to real world units

I need an optimal solution with a program I am working on. The program should take an image(black and white only) with some single black lined objects, like star, circle, rectangle and etc. After, a program should find a location of each black point on it and will track it. By this I according to those location I will make some computations to make my stepper mottor move accordingly. Imagine that there is marker and white board, and I want the picture on my pc to be drawn on whiteboard, by specifying the size .
I don't know, maybe there are some other ways beside the image, and what units is better, pixel based or ....?need some suggestions and recomendations.
Appreciate
With printing, scanning and monitors, there is the term DPI (Dot-Per-Inch), this is what you need to inspect to determine the real world size of an image. Compare the DPI of the device, by the number of pixels in your image.
Note, DPI is represented in dots per SQUARE inch.
I don't know how to do that with C# , but you can OpenCV and it wrapper for c# Emgu, you can read the image that you have and convert it to YCbCr color model and, you can you the contours function or minmaxloc function .

Algorithm to detect if a pixel is within a boundary

We're currently creating a simple application for image manipulation in Silverlight, and we've hit a bit of a snag. We want users to be able to select an area of an image (either by drawing a freehand line around their chosen area or by creating a polygon around it), and then be able to apply effects to the pixels within that selection.
Creating a selection of images is easy enough, but we want a really fast algorithm for deciding which pixels should be manipulated (ie. something to detect which pixels are within the user's selection).
We've thought of three possibilities so far, but we're sure that there must be a really efficient and quick way of doing this that's better than these.
1. Pixel by pixel.
We just go through every pixel in an image and check whether it's within the user selection. Obviously this is far too slow!
2. Using a Line Crossing Algorithim.
The type of thing seen here.
3. Flood Fill.
Select the pixels along the path of the selection and then perform a flood fill within that selection. This might work fine.
This must a problem that's commonly solved, so we're guessing there's a ton more solutions that we've not even thought of.
What would you recommend?
Flood fill algorithm is a good choice.
Take a look at this implementation:
Queue-Linear Flood Fill: A Fast Flood Fill Algorithm
You should be able to use your polygon to create a clipping path. The mini-language for describing polygons for Silverlight is quiet well documented.
Alter the pixels on a copy of your image (all pixels is usually easy to modify than some pixels), then use the clipping path to render only the desired area of the changes back to the original image (probably using an extra buffer bitmap for the result).
Hope this helps. Just throwing the ideas out and see if any stick :)

Categories

Resources