How do I generate a trimap from a binary mask? [closed] - opencv

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
The community reviewed whether to reopen this question 6 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm trying to implement this paper right now:
Automatic Skin and Hair Masking Using Convolutional Neural Networks
I've gotten the FCN and CRF part working, and I found the code to generate the alpha mask once I have the trimap.
I'm stuck on the part between (c) and (d), though.
How do I generate a trimap given the binary mask? The paper says:
We apply morphological operators on the binary segmentation
mask for hair and skin, obtaining a trimap that indicates
foreground (hair/skin), background and unknown pixels. In
order to deal with segmentation inaccuracies, and to best capture
the appearance variance of both foreground and background,
we first erode the binary mask with a small kernel,
then extract the skeleton pixels as part of foreground constrain
pixels. We also erode the binary mask with a larger kernel to
get more foreground constrain pixels. The final foreground
constrain pixels is the union of the two parts. If we only keep
the second part then some thin hair regions will be gone after
erosion with a large kernel. If a pixel is outside the dilated
mask then we take it as background constrain pixel. All other
pixels as marked as unknown, see figure 2 (d).

OpenCV supports morphological operations.
Please see this tutorial explaining how to use erode and dilate functions.

Related

What is the difference between convert -unsharp and convert -adaptive-sharpen in ImageMagick [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I understand that the the convert -unsharp from ImageMagick is using Unsharp Masking to sharpen the image. What kind of algorithm is behind convert -adaptive-sharpen? When I want to sharpen my lanscape images, which algorithm should I use? What are the advantages and disadvantages for the two algorithms?
I'm not an expert on the algorithm, but both operations achieve the same goal by creating a "mask" to scale the intensity of the sharpening. They differ on how the generate the "mask", and the arithmetic operations.
With -unsharp
Given...
For demonstration, let's break this down into channels.
Create a "mask" by applying a Gaussian blur.
Apply the gain of the inverse mask if threshold applies.
Ta-Da
With -adaptive-sharpen
Given...
For demonstration, let's break this down into channels (again).
Create "mask" by applying edge detection, and then Gaussian blur.
Apply sharpen, but scale the intensity against the above mask.
Fin
Which command will give the better results for normal outdoor images?
That depends on the subject matter. It's a good rule-of-thumb to use -adaptive-sharpen if the image contains large empty space (sky, sea, grass, &etc), or bokeh/blurred background. Else -unsharp will work just fine.

Why adding salt and pepper noise must be on grayscale image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I know if my question is pretty basic but I can't seem to find the answer on the internet. So I want to know the people tend to convert image into grayscale prior to adding salt and pepper noise?
It's implied in the name, salt and pepper are black and white. Noise is always present to some degree in images captured by cameras. As such it is often added to images during testing to check if the solution is robust to real world cases.
Noise in a color image can take two forms, chromatic noise or luminance noise. Luminance noise will be consistent across color channels, chromatic noise will vary by color channel. Chromatic noise is caused by the camera sensor's sensitivities to the various wavelengths of light. Luminance noise is caused by the camera system's electrical "noise floor" which is a product of overall sensitivity.
You can add noise in grayscale or in color, the process is the same. For academic purposes, writing a solution that works on a grayscale image with noise is a similar, though possibly less complex, problem than writing a solution for full color images. Computer vision is often only done on grayscale images, so it is common to test against grayscale images.

How to subtract color pixels [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
A lot of research papers that I am reading these days just abstractly write image1-image2
I imagine they mean gray scale images. But how to extend these to color images ?
Do I take the intensities and subtract ? How would I compute these intensities by taking the average or by taking the weighted average as illustrated here?
Also I would prefer if you could quote the source of this as well preferably from a research paper or a textbook.
Edit: I am working on motion detection where there are tons of algorithms which create a background model of the video(image) and then we subtract the current frame(again a image) from this model. We see if this difference exceeds a given threshold in which case we classify the pixel as foreground pixel. So far I have been subtracting the intensities directly but don't know whether other approach is possible.
Subtraction directly at RGB space or after converting to grayscale space is possible to miss useful information, and at the same time induce many unwanted outliers. It is possible that you don't need the subtraction operation. By investigating the intensity difference between background and object at all three channels, you can determine the range of background at the three channels, and simply set them to zero. This study demonstrated such method is robust against non-salient motion (such as moving leaves) with the presence of shadows at various environments.

License plate detection [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
My task is to pin-point where is the plate number in an image. The image does not only contain the plate number. It may contain the whole car or anything. I used gaussian blur then grayscale then contrast then laplacian of gaussian to detect the edges.
Now, I am at loss on how to detect where is the plate number in the image. I am not going to read the license number, just make the system know where is the license number.
Can you direct me to a study regarding this? Or perhaps the algorithm that can be used to do this.
Thank you!
I think a more robust way to tackle this is a train a detector if you have enough training images of the license plate in different scenarios. Few things you can try is Haar cascade classifier in Opencv library. It does a multiscale detection of learned patterns.
You could try edge detection or some form of Hough transforms.
For example, do edge detection and then look for rectangles (or if the images aren't straight on, parallelograms) in the image. If you know that the plates will all be the same shape and size ratios, you can use that to speed up your search.
EDIT:
Found this for you.
Using some feature recognition algorithm e.g. SIFT would be a good starting point. Do you need real-time recognition or not? I recommend trying to tighten search space first, for example by filtering out regions from the image (is your environment controlled or not?). There is an article about recognising license plates using SIFT here (I just skimmed it but it looks reasonable).
License-plates or number plates of vehcles come with 2 striking properties.
They have specified color pattern (Black letters on white, yellow or gray background)
Aspect ratio
These properties can be used to extract only the license plate. First threshold the image using adaptive thresholding. Then find contours in the image with aspect ratio in a close range to standard value. This method should work for most of the cases. You can also try erosion followed by dilation of thresholded image to remove noise.

Finding repeating patterns/images in images [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I've been looking around for some papers (or info) on this topic.
To avoid a misunderstanding: I'm not talking about finding a supplied pattern in multiple locations.
Repeating patterns can also be understood to mean repeating images. The definition of pattern here isn't abstract. Imagine, for instance, a brick wall. The wall is composed of individual bricks. A picture of the wall is composed of the repeating image of a brick.
The solution must preferably find the largest repeating pattern. Large in this context can be defined two ways: pixel area or number of repetitions.
In the above example, you can cut the bricks in half. In order to make a brick, you can rotate a segment and attach the halves. While the complete brick is the largest repeating image in terms of pixel area, there are 2x more repetitions of half blocks.
Any thoughts?
A number of methods come to mind:
Fourier Transformation of the image
Wavelet Analysis
Autocorrelation
I'd start with fourier analysis: Any shape repeating in a regular pattern in the image creates a very distinct spatial frequency spectrum: One major frequency and some harmonics.
I'm not sure if this is what you're looking for, but I suggest searching for "Texture based segmentation". Take a look at this bibliography, for example: http://www.visionbib.com/bibliography/segment366.html

Resources