find region in image emgucv - c#

example image
after image
how to find rectangle region in image?
It can be not exactly.
i tried to use "CvInvoke.findContours" but i failed because don't know how to use.
please tell me what should i do
i need function that return region rectangles, or some hints please..
sorry and thanks.

You'll want to create an image where the regions that you want are highlighted and the regions you don't want are black. To do this, I would do an adaptive threshold (you'll want to convert the image to black and white and then use the invert threshold option to highlight the non-white areas).
Then I would use morphology (dilation followed by erosion, or 'closing') to remove the noise. The image should now have white blobs on the regions you're interesting in and be black elsewhere. The final steps will be find contours, follows by looping over each contour and finding their bounding boxes.
You'll want to read up on each of these topics, but that approach should work for what you want. Opencv's documentation isn't great, and EmGU's bindings adds another layer of confusion, but be patient and you'll get the hang of it.
Adaptive threshold:
https://docs.opencv.org/3.3.1/d7/d4d/tutorial_py_thresholding.html
Morphology: https://docs.opencv.org/2.4/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html
find contours:
https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours#findcontours
bounding rect:
https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=boundingrect#boundingrect

here is the link that contains
shape detection using emgu.

Related

Change polygon color programmatically of a digitized image

I don't have knowledge about ArcGIS... But I am working on a program related to that...
I have to do-
Load digitized image in my windows application and after that i have to change polygon color according to client need.
Actually the image is a satellite/drone image, and in ArcGIS my colleague plotting polygons.
I have to load that digitized image in windows application and according to requirement (like differentiate polygons according to area; polygon having area between 0 to 1000 sq.ft. must be in yellow;between 1001 to 1500 - red; etc) I have to change that polygons color programmatically using C#
So my question is, In which format that digitized image must be? so that i can change polygon color...
One more thing I didn't tried anything to accomplish this... Because I don't know about this... So feel free to suggest any relevant solution....
EDIT:
Here are the to images, one is before digitizing and another is a demo of after digitizing
Thanks in Advance

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.

C# How do use one image as a cookie cutter for removing part of another image

I have an image with a decent portion of it transparent. It's the result of a green screen process. I need to overlay a filter on top of the image without laying on top of the transparent portions. You could think of it like using the base image as a cookie cutter to remove a matching shape from the filter image so I can merge them.
I've tried combing through AForge but I don't see anything helpful and google is returning all sorts of garbage. If anyone has any suggestions on where to start or alternate methods I would appreciate it.
I came up with a solution that works for me but may not answer the question directly, as I asked it. Someone else may find this useful though.
I Iterated through image I wanted to cut out. At each pixel position I would use that same position to check the "cookie cutter" image and if the Alpha channel was 0, I would then set the pixel value on the base image to 0. I was basically setting everything other than the cookie cutter shape to transparent.
A caveat is this only works if the image are the exact same size and you can't easily change the location of the where you want the cutout.

Detecting a blob of color in an image

I have an image that is a depth heatmap that I've filtered out anything further away than the first 25% of the image.
It looks something like this:
There are two blobs of color in the image, one is my hand (with part of my face behind it), and the other is the desk in the lower left corner. How can I search the image to find these blobs? I would like to be able to draw a rectangle around them if possible.
I can also do this (ignore shades, and filter to black or white):
Pick a random pixel as a seed pixel. This becomes area A. Repeatedly expand A until A doesn't get any bigger. That's your area.
The way to expand A is by looking for neighbor pixels to A, such that they have similar color to at least one neighboring pixel in A.
What "similar color" means to you is somewhat variable. If you can make exactly two colors, as you say in another answer, then "similar" is "equal". Otherwise, "similar" would mean colors that have RGB values or whatnot where each component of the two colors is within a small amount of each other (i.e. 255, 128, 128 is similar to 252, 125, 130).
You can also limit the selected pixels so they must be similar to the seed pixel, but that works better when a human is picking the seed. (I believe this is what is done in Photoshop, for example.)
This can be better than edge detection because you can deal with gradients without filtering them out of existence, and you don't need to process the resulting detected edges into a coherent area. It has the disadvantage that a gradient can go all the way from black to white and it'll register as the same area, but that may be what you want. Also, you have to be careful with the implementation or else it will be too slow.
It might be overkill for what you need, but there's a great wrapper for C# for the OpenCV libraries.
I have successfully used OpenCV in C++ for blob detection, so you might find it useful for what you're trying to do.
http://www.emgu.com/wiki/index.php/Main_Page
and the wiki page on OpenCV:
http://en.wikipedia.org/wiki/OpenCV
Edited to add: Here is a blobs detection library for Emgu in C#. There is even some nice features of ordering the blobs by descending area (useful for filtering out noise).
http://www.emgu.com/forum/viewtopic.php?f=3&t=205
Edit Again:
If Emgu is too heavyweight, Aforge.NET also includes some blob detection methods
http://www.aforgenet.com/framework/
If the image really is only two or more distinct colours (very little blur between colours), it is an easy case for an edge detection algorithm.
You can use something like the code sample from this question : find a color in an image in c#
It will help you find the x/y of specific colors in your image. Then you could use the min x/max x and the min y/max y to draw your rectangles.
Detect object from image based on object color by C#.
To detect a object based on its color, there is an easy algorithm for that. you have to choose a filtering method. Steps normally are:
Take the image
Apply ur filtering
Apply greyscalling
Subtract background and get your objects
Find position of all objects
Mark the objects
First you have to choose a filtering method, there are many filtering method provided for C#. Mainly I prefer AForge filters, for this purpose they have few filter:
ColorFiltering
ChannelFiltering
HSLFiltering
YCbCrFiltering
EuclideanColorFiltering
My favorite is EuclideanColorFiltering. It is easy and simple. For information about other filters you can visit link below. You have to download AForge dll for apply these in your code.
More information about the exact steps can be found here: Link

How do I get the coordinates of some text thats part of an image?

I want to cut up the image based on various text markers placed around within it. The font/size of the marker is up to me.
I know commercial OCR packages provide this in their APIs but I'm hoping I can code this up myself.
Ideally I wouldn't have to go pixel to pixel and compare against an image of the marker text.
I'm good with C++/C#, Java, PHP and an other language where a library like this exists...
Ideally I wouldn't have to go pixel to
pixel and compare against an image of
the marker text.
Well, if you're trying to find the marker image, then that's exactly what you'd have to do.
Here's an idea... Set the marker text to a particular color, then process the background image to make sure that it doesn't have any pixels of that color. Finding the markers should become a lot easier at that point.
A barcode would be easier to detect than a text marker. You can always place them together, with the barcode being used for automatic position detection and the text for human user.
If you want to do a really sufisticated solution, you could use the hough transform. It is often used for augumented reality stuff - there it is necessary to find a certain marker in an image. Ofc you would have to change your markers a bit, would this be possible? ;-)
The hough will give you the position of your marker lines and thus the area which you want to cut out.
Here is a link about hough, but there are many others though.
Hough
Or this one
Wiki
A fiduciary marker would be better than text. That's what they use for augmented reality and such.
If the text is always the same size, shape, and oriented in the same direction, you could use normalized cross-correlation.
"Ideally I wouldn't have to go pixel to pixel and compare against an image of the marker text."
Well how else are you going to do it? You're only going to search in part of the image?

Categories

Resources