Cognex Vision Suite (ViDi) - Remove part for a image - image-processing

I'm new to cognex world, so if anyone can help I will be thankful.
I have a image, how can I remove a Region of a Image?
So my ROI is a box, but there is a smaller box inside of that bigger box that is not important. So my ROI will be the bigger box less the smaller box.
I tried filters, but filter a new image with the size of the region (ROI filter).
How can I do this?

You can use the mask to ignore a part of the image. Some tools allow different "uses" of the mask so make sure it fits what you need.
For example, segmentation tools (red tools) can use the masked region as an extra channel of the image.

Related

Image Processing - Film negative cutting

I'm trying to figure out how to automatically cut some images like the one below (this is a negative film), basically, I want to remove the blank parts at the top and at the bottom. I'm not looking for complete code for it, I just want to understand a way to do it. The language is not important at this point, but I think this kind of thing normally is accomplished with Python.
I think there are several ways to do that, ranging from simple to complex. You can see the problem as detecting white rectangles or segmenting the image I would say.
I can suggest you opencv (which is available in more than one language, among which python), you can have a look here at the image processing examples
First we need to find the white part, then remove it.
Finding the white part
Thresholding
Let's start with an easy one: thresholding
Thresholding means dividing the image into two parts (usually black and white). You can do that by selecting a threshold (in your case, the threshold would be towards white - or black if you invert the image). By doing so, however, you may also threshold some parts of the images (for example the chickens and the white part above the kid). Do you have information about position of the white stripes? Are they always on top and bottom of the image? If so, you can apply the thresholding operation only on the top 25% and bottom 25% of the image. You would then most likely not "ruin" the image.
Finding the white rectangle
If that does not work or you would like to try something else, you can see the white stripes as rectangles and try to find their contour. You can see how in this tutorial. In this case you do not get a binary image, but a bounding box of the white areas. You most likely find the chickens also in this case, but by looking at the bounding box is easy to understand which one are correct and which one not. You can also check this calculating areas of the bounding box (width * height) and keep only the big ones.
Removing the part
Once you get the binary image (white part and not white part) or the bounding box, you have to crop the image. This also can be done in several ways, but I think the easiest one would be cropping by just selecting the central part of the image. For example, if the image has H pixels vertically, you would keep only the pixel from H1 (the height of the first white space) to H-H2 (where H2 is the height of the second white space). There is no tutorial on cropping, but several questions here on SO, as for example this one.
Additional notes
You could use more advanced segmentation algorithms as the Watershed one or even learn and use advanced techinques as machine learning to do that (here an article), as you can see the rabbit hole is pretty deep in this case. But I believe that would be an overkill and already the easy techniques would give you some results in this case.
Hope this was helpful and have fun!

How to improve Grabcut in the case when the bottom part of the image isn't a part of the background?

When I'm running Grabcut on an image,
I set the bounding box of grabcut to the edges of the image itself.
However, since the bottom of the image is a part of the foreground not background, it cuts out the lower part.
Is there any way of preventing this, such as setting the boundary box only to the top, left and right?
GrabCut needs the boundary to define what is "outside" so it can compute a background color model. Depending on your API/interface you might be able to define "outside" only from the right-top and left parts of the image, leaving the bottom "inside".
Assuming you are using cv::grabCut, you may define the initial rect to exceed the bottom part of the image, in that case the algorithm should not consider the lower part to be "obvious background".
As the background in this image is quite clean, you may try some rules to segment the foreground in this case. For examples, why don't you remove the “relatively” white regions. The color of background can be heuristically extracted from the boundary region of images.
If there is cluttered background in your data set, you may try to detect a tighter bounding box for the human by using detectors, such as DPM, or R-CNN. They already provide some powerful models for human detection. Based on the detected box, I suppose the result of grabcut should be better.
Anyway, it should be helpful to provide some more examples for analysis.
classic gab cut implemented in openCV has 6 Gaussian mixture models corresponding to 6 centroids in 3D color space - more than you need to model the image above. Thus your problem is in setting correct labels. You have to set not only bounding box or ROI but 3 regions with 3 labels - FG, BG, PROBABLY_BG (partition the image). The former two will contribute to the models of foreground and background on the basis of which the latter label will be the only region where the boundary is refined. In other words, you did not do correct initialization of grab cut with three labels. See this, for example How to set a mask image for grabCut in OpenCV?

Image Segmentation/Background Subtraction

My current project is to calculate the surface area of the paste covered on the cylinder.
Refer the images below. The images below are cropped from the original images taken via a phone camera.
I am thinking terms like segmentation but due to the light reflection and shadows a simple segmentation won’t work out.
Can anyone tell me how to find the surface area covered by paste on the cylinder?
First I'd simplify the problem by rectifying the perspective effect (you may need to upscale the image to not lose precision here).
Then I'd scan vertical lines across the image.
Further, you can simplify the problem by segmentation of two classes of pixels, base and painted. Make some statistical analysis to find the range for the larger region, consisting of base pixels. Probably will make use of mathematical median of all pixels.
Then you expand the color space around this representative pixel, until you find the highest color distance gap. Repeat the procedure to retrieve the painted pixels. There's other image processing routines you may have to do such as smoothing out the noise, removing outliers and background, etc.

Opencv how to ignore small parts on image

I need a little help in Opencv, I´m a beginner and don´t know all functions yet.
I´m trying to do an OCR in my licence plate, it´s an Brazilian plate. So after some image processing like cvCvtColor,cvCanny,cvFindContours and cvDrawContours, I get images like this:
It´s a fake image, I mounted this image because I don´t want to publish my real plate on the web. On my real image, there is only black and white color I painted some parts on this example because I want ignore this parts. Red color it´s a city name, yellow color is a hyphen separator and green color is the hole to fix the plate on car. I need to know if there is a way to ignore this small parts and recognize only big parts, so after this filter i can do my OCR processing. Any help?
I'm not sure if it helps you in other situations but in this situation you can remove small contours using erosion or simply using contourArea for calculating contour's area (and remove contour if it's area is too small).

Simple OpenCV example to measure Size of Object on a screen

following up on my other question, do you guys know a good example in OpenCV, with a simple Black/White-Calibration Picture and appropriate detection-algorithms?
I just want to show some B&W-image on a screen, take a picture of that image from afar and calculate the size of the shown image, to calculate the distance to said screen.
Before I invent the wheel again, I recon this is so easy that it could be achieved through many different ways in OpenCV, yet I thought I'd ask if there's a preferred way around, possibly with some sample code.
(I got some face-detection code running using haarcascade-xml files already)
PS: I already have the resolution/dpi-part of my screen covered, so I know how big a picture would be in cm on my screen.
EDIT:
I'll make it real simple, I need:
A pattern, that is easily recognizable in an Image. Right now I'm experimenting with a checkerboard. The people who made ARDefender used this.
An appropriate algorithm to tell me the exact pixel coordinates of pattern 1) in a picture using OpenCV.
Well, it's hard to say which image is the best for recognition - in different illumination any color could be interpret as another color. Simple example:
As you can see both traffic signs have red color border but even on one image upper sign border is obviously not red.
So in my opinion you should use image with many different colors (like a rainbow). And also you said that it should be easy recognizable in different angles. That's why circle shape is the best for it.
That's why your image should look like this:
So idea of detection such object is the following:
Make different color segmentation (blue, red, green etc). For this use HSV color space.
Detect circles of specific color on image.
That area which has the biggest count of circles seems to be your object.
you just have to take pictures of your B&W object from several known distances (1m, 2m, 3m, ...) and then for each distance check the size of your object in the corresponding image.
From those datas, you will be able to create a linear function giving you the distance from the size in pixels (y = ax + b should do ;) ), translate it into your code and you're done.
Cheers

Resources