We have an RGB image. I want to apply adaptive thresholding on it. How can we find the threshold value??? I think we can separately find the threshold value of each channel but what next is the confusion?? or if you can provide some better solution it would be appreciable. Thanks.
You wrote that you want to apply thresholding so I assume that you want binarized image as output. Is there any special reason that you want perform thresholding on each channel separately? If not, try convert image to grayscale and then apply thresholding. If you want you could apply thresholding on each channel separately and then merge output binarized images from each channel into one output but I don't know why you wan to do it.
Related
I am trying to use an binarize images similar to the following image:
Basically, I want all non white to become black but threshold in OpenCV is giving fringing (JPEG Artifacts). I even tried Otsu thresholding but some parts of the colors don't work so well.
Is there any simple way of doing this binarization properly?
Turn to greyscale, apply 5x5 blur filter, and binarize? The blur will smooth the ringing artifacts.
After quite some trial and error, turns out Morphological Closing before thresholding using a large value turns out to be most suitable for the next stage of what I am working on. But it does cause some loss of shape info.
Given that you have to use JPEG for this project, the one thing you can do use all one quantization tables. That is usually done through "quality" settings. You want an encoder that will allow you to do no quantization.
I have a few objects in a black background.I would like to threshold the image and transform the objects in 1 and the black background into 0.
I am not sure how to choose my threshold to isolate the black background.
You can do this simply by the following step.
Load your image.
Convert to gray-scale.
Apply binary threshold which will create the result as your requirement.
Here you can see a good explanation about Basic Thresholding Operations using OpenCV with example.
One of the simplest thing to do is using the OpenCV's threshold function on the whole image and let the threshold value be choosen automatically by means of the Otsu's algorithm (the type argument of the threshold function should be ORed with the constant THRESH_OTSU).
Otsu's original work is: OTSU, Nobuyuki. A threshold selection method from gray-level histograms. Automatica, 1975, 11.285-296: 23-27.
This approach may work very well or it may fail miserably... it depends, as always, on your images.
How to count corn trees accurately with opencv based on the following image? I have tried HSV conversion with inRange but got nothing so far.
Is there a way for counting the trees correctly? Even with noise reduction I think that it won't count it property.
I chose a template as follows...
and when I tried to run a template match I got the following match..
The match was fine as because I chose the template from that part of the image.However the result image containing the values of the extent of match at different areas of the full image when threshold-ed looked like this..
So you can see that if you count the white patches (neglecting the small noises) you almost get the possible number of crops...!!
EDIT
More precise result you can get if you try the template matching in the green plane of the RGB image
Your problem is easier to solve when implementing few simple preprocessing steps. Look at the result I obtained:
Steps:
Convert RGB to LAB image
Extract A channel (discard L, B channels)
Stretch/Maximize image contrast
Use Otsu's optimal threshold selection for binarization
Invert the image so that foreground is white, background is black
Based on this image template matching or other detection methods should work even better.
I'm looking for a possibility to convert raster images to vector data using OpenCV. There I found a function cv::findContours() which seems to be a bit primitive (more probably I did not understand it fully):
It seems to use b/w images only (no greyscale and no coloured images) and does not seem to accept any filtering/error suppresion parameters that could be helpful in noisy images, to avoid very short vector lines or to avoid uneven polylines where one single, straight line would be the better result.
So my question: is there a OpenCV possibility to vectorise coloured raster images where the colour-information is assigned to the resulting polylinbes afterwards? And how can I apply noise reduction and error suppression to such a algorithm?
Thanks!
If you want to raster image by color than I recommend you to clusterize image on some group of colors (or quantalize it) and after this extract contours of each color and convert to needed format. There are no ready vectorizing methods in OpenCV.
What's the best set of image preprocessing operations to apply to images for text recognition in EmguCV?
I've included two sample images here.
Applying a low or high pass filter won't be suitable, as the text may be of any size. I've tried median and bilateral filters, but they don't seem to affect the image much.
The ideal result would be a binary image with all the text white, and most of the rest black. This image would then be sent to the OCR engine.
Thanks
There's nothing like the best set. Keep in mind that digital images can be acquired by different capture devices and each device can embed its own preprocessing system (filters) and other characteristics that can drastically change the image and even add noises to them. So every case would have to be treated (preprocessed) differently.
However, there are commmon operations that can be used to improve the detection, for instance, a very basic one would be to convert the image to grayscale and apply a threshold to binarize the image. Another technique I've used before is the bounding box, which allows you to detect the text region. To remove noises from images you might be interested in erode/dilate operations. I demonstrate some of these operations on this post.
Also, there are other interesting posts about OCR and OpenCV that you should take a look:
Simple Digit Recognition OCR in OpenCV-Python
Basic OCR in OpenCV
Now, just to show you a simple approach that can be used with your sample image, this is the result of inverting the color and applying a threshold:
cv::Mat new_img = cv::imread(argv[1]);
cv::bitwise_not(new_img, new_img);
double thres = 100;
double color = 255;
cv::threshold(new_img, new_img, thres, color, CV_THRESH_BINARY);
cv::imwrite("inv_thres.png", new_img);
Try morphological image processing. Have a look at this. However, it works only on binary images - so you will have to binarize the image( threshold?). Although, it is simple, it is dependent on font size, so one structure element will not work for all font sizes. If you want a generic solution, there are a number of papers for text detection in images - A search of this term in google scholar should provide you with some useful publications.