I am working on a project where I want to detect the pores in a given skin image.
I have tried various methods(HoughCircles, BlobDetection and Contours) from OpenCv using Java, however, I am unable to proceed.
HoughCircles is showing me all false circles and same is the case with contours.
My current code uses blob detection technique which is also not showing what is required. Sample code is written below:
public void detectBlob() {
Mat orig = Highgui.imread("skin_pore.jpg",Highgui.IMREAD_GRAYSCALE);
Mat MatOut= new Mat();
FeatureDetector blobDetector;
blobDetector = FeatureDetector.create(FeatureDetector.SIFT);
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
blobDetector.detect(orig,keypoints1);
org.opencv.core.Scalar cores = new org.opencv.core.Scalar(0,0,255);
org.opencv.features2d.Features2d.drawKeypoints(orig,keypoints1,MatOut,cores,2);
Highgui.imwrite("PhotoOut.jpg", MatOut);
}
public static void main(String args[]) {
BlobDetection bd = new BlobDetection();
bd.detectBlob();
}
When I tried the same code using FeatureDetector.SIMPLEBLOB instead of FeatureDetector.SIFT it shows almost 0 blobs.
The output and source images are attached for the above code. Source Image
Output Image using SIFT
Is there any other algorithm which can help in achieving the result or what can be the appropriate approach to achieve this?
As you did not ask anything in your question I won't give you an answer. More some general advice.
That you tried to solve that problem using the named algorithms clearly shows that you have absolutely no clue what you are doing. You lack the very basics of image processing.
It's like trying to win vs decent chess player if you don't even know how the figures can move.
I highly recommend that you get yourself a beginners book, read it and make sure you understand its contents. Then do some more research on the algorithms you want to use, befor you use them.
You cannot take some arbitrary image, feed it into some random feature detection algorithm you find on the internet and expect to succeed.
Hough transform for cirles for example is good for finding circle shaped contours of a roughly known radius. If you know how it works internally you will know why it is not a good idea to use it on your image.
https://en.wikipedia.org/wiki/Circle_Hough_Transform
Blobdetection and contour based algorithms might work, but only after a lot of pre-processing. Your image is not very "segmentation-friendly"
https://en.wikipedia.org/wiki/Image_segmentation
https://en.wikipedia.org/wiki/Blob_detection
A SIFT detector usually has to be taught using reference images and reference keypoints. I don't see this either in your code.
https://en.wikipedia.org/wiki/Scale-invariant_feature_transform
Please note that reading those wikipedia articles will only give you a first idea of what's going on. You have to read a lot more.
Always start at the beginning of your processing chain. Can you get better images? (Better means more suitable for what you want to detect). This is like 10% camera and 90% illumination. I don't think detecting skin pores is a classical task for shitty cellphone pictures so why not put a bit effort into your imaging setup?
First rule of image processing: crap in = crap out. You should at least change the angle of illumination or even better approach like shape from shading.
An image optimized for the detection you have to do is cruicial. It will make image processing so much easier.
Then pre-processing: How can you transform the image you have into something you can easily extract features from?
And so on...
Related
I found out that there is Chamfer Matching available in OpenCV. I can see there is a function chamferMatching() for C++ and there seems to be a way to use it in Python, too. However, I was unable to find how to use this feature in Java. I am using OpenCV 3.1 Where can I find it in the Java interface? Is it even available there?
If not, what can I use instead? I am trying to recognize fruits. For now apples in particular. I want to match precomputed apple contour to found contours in the image (chamfer matching). After finding a possible apple I am planning to use a classifier to make sure the color and texture are correct.
Template matching seems to be a bad choice because it doesn't work with recognizing rotated objects. I am wondering if I can use Feature Descriptors. Note that I am not trying to recognize a particular apple and I don't know if Feature Descriptors are good for this.
Any thoughts?
EDIT: Ok, I decided to use the findContours() function to get all of the contours in the image, then filter them by area and compare each of the filtered contours with others, designated as templates from training, using matchShapes(). I implemented this and it is not working right (because findContours() is not detecting the apple contours) but I'll post another question with this specific problem. Here I want to ask if this way sounds ok and if there is a better way to detect and compare contours.
Ok, I figured it out. There seems to be no Chamfer Matching in OpenCV. It is implemented in JavaCV and there is no sign of it in the native code. Since I'm using OpenCV for Java it is not a good solution for me.
This answer helped me a lot. It is in C++ but it can easily be written in Java.
Initially, I am training the program using a database of 100 images of green apples. The training is actually just storing the largest contour of every photo in a file.
The key to my problem was dividing the image into the 3 different channels resulting in 3 different grayscale images. I transform them using Canny and dilate. Now I check every one of them for contours and it is very likely I will detect the contours of the apple in at least one of them. Once I have all the contours from the 3 images, I filter them by size and then comparing them with every single contour from the training data. If the contour is close enough to one of them I assume it is a contour of an apple.
There seems to be quite a lot of false positives but they will be filtered out when my coleague implements the module doing checks for color and texture of the selected contours (their content).
Here's our project's repository if it would be of help to anyone.
I've not found anything here or on google. I'm looking for a way to identify shapes (circle, square, triangle and various other shapes) from a image file. Some examples:
You get the general idea. Not sure if BoofCV is the best choice here but it looks like it should be straightforward enough to use, but again I know nothing about it. I've looked at some of the examples and I though before I get in over my head (which is not hard to do some days), I thought I would ask if there is any info out there.
I'm taking a class on Knowledge Based AI solving Ravens Progressive Matrix problems and the final assignment will use strictly visual based images instead of the text files with attributes. We are not being graded on the visual since we only have a few weeks to work on this section of the project and we are encouraged to share this information. SOF has always been my go to source for information and I'm hoping someone out there might have some ideas on where to start with this...
Essentially what I want to do is detect the shapes (?? convert them into 2D geometry) and then make some assumptions about attributes such as size, fill, placement etc, create a text file with these attributes and then using that, send it through my existing code based that I wrote for my other projects to solve the problems.
Any suggestions????
There are a lot of ways you can do it. One way is to find the contour of the shape then fit a polygon to it or a oval. If you git a polygon to it and there are 4 sides with almost equal length then its a square. The contour can be found with binary blobs (my recommendation for the above images) or canny edge.
http://boofcv.org/index.php?title=Example_Fit_Polygon
http://boofcv.org/index.php?title=Example_Fit_Ellipse
I'm looking for the most optimal way of extracting single color on background and replace it with some picture on the fly in JavaCV. I wrote very simple method reading pixel by pixel and replacing it if the color is green for example.
This is very slow and even if I divided it into few threads it works dramatically slow.
This must be done on live so I have to find out some other method. Perhaps I will have to add some watermark as well after background replacing, so the application must be quite fast.
Does anybody can help me finding right way of doing it ?
I spend all day long trying to find other way of doing it, but.. all examples I have found doesn't work or maybe I do not know how to adopt them to my needs.
This guy (http://www.youtube.com/watch?v=WOEuE3D88b0) wrote that he is reading pixel by pixel - no way, or maybe he had very fast multi-core workstation. On my MacBook Pro 2.5 i5 it just doesn't work :(
I have used your example and I think that I have mixed it totally. I can see mask of moving me ( white on black background) and if I use CvCopy I can see background appearing at the places where white dots are.
Unfortunatelly his is not requested result, but I think I must be very close to it ;) I have to leave me and replace all static objects.
Could you please examine my code ?
private static final IplImage back = cvLoadImage("/Users/user/app/eclipse/JavaCV/resources/1.png", CV_LOAD_IMAGE_COLOR);
private static BackgroundSubtractorMOG2 bgs = new BackgroundSubtractorMOG2(30,16,false);
public static IplImage replacePixels2(IplImage img){
IplImage frame = cvCloneImage(img);
//bgs.getBackgroundImage(frame);
IplImage image = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U,1);
bgs.apply(frame, image, -1);
IplROI roi = new IplROI();
roi.xOffset(0);
roi.yOffset(0);
roi.width(frame.width());
roi.height(frame.height());
IplImage backImageWithRoi = frame.roi(roi);
cvCopy(back, backImageWithRoi, image );
return backImageWithRoi;
}
I also tried grabCut but this is extremely slow and can't be used in changing stream on live :(
Best Regards
Jan
Since JavaCV is an interface to OpenCV, then you must be able to perform Grabcut segmentation.
As answered here too.
I am looking for library routines for the image enhancement of (scientific) plots and diagrams. Typical examples are shown in
http://www.jcheminf.com/content/pdf/1758-2946-4-11.pdf
and Figure 3 of http://en.wikipedia.org/wiki/Anti-aliasing
These have the features that:
They usually use a very small number of primitives (line, character, circle, rectangle)
They are usually monochrome (black/white) or have a very small number of block colours
The originals have no gradients or patterns.
I wish to reconstruct the primitives and am looking for an algorithm to restore clean lines in the image before the next stage of analysis (which may include line detection and OCR). The noise often comes from :
use of JPGs (the noise is often seen close to the original primitive)
antialiasing
I require Free/Open Source solutions and would ideally like existing Java libraries. If there are any which already do some of the job or reconstructing lines that would be a bonus! For characters recognition I would be happy to isolate each character at this stage and defer OCR, though pointers to that would also be appreciated.
UPDATE:
I am surprised that even with a bounty there have been no substantive replies to the question. I am therefore investigating it myself. I still invite answers but they should go beyond my own answer.
ANSWER TO OWN QUESTION
Since there there have been no answers after nearly a week here is what I now plan:
I found mention of the Canny edge-detection algorithm on another SO post and then found:
[http://www.tomgibara.com/computer-vision/canny-edge-detector][2]
from Tom Gibara.
This is very easy to use in default mode and the main program is:
public static void main(String[] args) throws Exception {
File file = new File("c.bmp");
//create the detector
CannyEdgeDetector detector = new CannyEdgeDetector();
//adjust its parameters as desired
detector.setLowThreshold(0.5f);
detector.setHighThreshold(1f);
//apply it to an image
BufferedImage img = ImageIO.read(file);
detector.setSourceImage(img);
detector.process();
BufferedImage edges = detector.getEdgesImage();
ImageIO.write(edges, "png", new File("c.png"));
}
Here ImageIO reads and writes bitmaps. The unprocessed image is read as a 24-bit BMP (ImageIO seems to fail with lower colour range). The defaults are Gibara's out-of-the-box.
The edge detection is very impressive and outlines all the lines and characters. This bitmap
is converted to the edges
So now I have two tasks:
fit straight lines to the outlines, which are essentially clean "tramlines". I expect this to be straightforward for clean diagrams. I'd be grateful for any mention of Java libraries to fit line primitives to outlines.
recognize the characters. Gibara has done an excellent job of separating them and so this is an exercise of recognising the individual glyphs. I can use the outlines to isolate the individual pixel maps for each glyph and then pass these to JavaOCR. Alternatively the outlines may be good enough to recognize the characters directly. I do NOT know what the font is, but most characters are in the 32-255 range and I believe I can build up heuristic maps.
See How do I properly load a BufferedImage in java? for loading bitmaps in Java
Java Library
OpenCV is the go-to library for computer vision tasks like this. There are Java bindings here: http://code.google.com/p/javacv/ . OpenCV covers everything from basic image processing filters to high-level object and motion detection algorithms.
Line Detection
For detecting straight lines, try the Hough Transform. The OpenCV Tutorials have a good explanation: http://opencv.itseez.com/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html#how-does-it-work
The classical Hough transform outputs infinite lines, but OpenCV also implements a variant called the Probabilistic Hough Transform that outputs line segments. It should give what you need. The original academic paper is here: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.9440&rep=rep1&type=pdf
Once you detect line segments, you might want to detect linked line segments and join them together. For your simple images, you will probably do just fine with a brute-force comparison of all segment endpoints. If you detect more than one endpoint within a small radius, say 2 pixels, join them together to make sure your lines are continuous. You can also measure the angle between joined line segments to detect polygons.
Circle Detection
There is another version of the Hough transform that can detect circles, explained here: http://opencv.itseez.com/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html#hough-circle
I wish to reconstruct the primitives and am looking for an algorithm
to restore clean lines in the image before the next stage of analysis
(which may include line detection and OCR).
Have you looked at jaitools? ( http://code.google.com/p/jaitools/ ).
They have API for vectorizing graphics which are quite fast and flexible; see API and docs here: http://jaitools.org/
Here’s my task which I want to solve with as little effort as possible (preferrably with QT & C++ or Java): I want to use webcam video input to detect if there’s a (or more) crate(s) in front of the camera lens or not. The scene can change from "clear" to "there is a crate in front of the lens" and back while the cam feeds its video signal to my application. For prototype testing/ learning I have 2-3 images of the “empty” scene, and 2-3 images with one or more crates.
Do you know straightforward idea how to tackle this task? I found OpenCV, but isn't this framework too bulky for this simple task? I'm new to the field of computer vision. Is this generally a hard task or is it simple and robust to detect if there's an obstacle in front of the cam in live feeds? Your expert opinion is deeply appreciated!
Here's an approach I've heard of, which may yield some success:
Perform edge detection on your image to translate it into a black and white image, whereby edges are shown as black pixels.
Now create a histogram to record the frequency of black pixels in each vertical column of pixels in the image. The theory here is that a high frequency value in the histogram in or around one bucket is indicative of a vertical edge, which could be the edge of a crate.
You could also consider a second histogram to measure pixels on each row of the image.
Obviously this is a fairly simple approach and is highly dependent on "simple" input; i.e. plain boxes with "hard" edges against a blank background (preferable a background that contrasts heavily with the box).
You dont need a full-blown computer-vision library to detect if there is a crate or no crate in front of the camera. You can just take a snapshot and make a color-histogram (simple). To capture the snapshot take a look here:
http://msdn.microsoft.com/en-us/library/dd742882%28VS.85%29.aspx
Lots of variables here including any possible changes in ambient lighting and any other activity in the field of view. Look at implementing a Canny edge detector (which OpenCV has and also Intel Performance Primitives have as well) to look for the outline of the shape of interest. If you then kinda know where the box will be, you can perhaps sum pixels in the region of interest. If the box can appear anywhere in the field of view, this is more challenging.
This is not something you should start in Java. When I had this kind of problems I would start with Matlab (OpenCV library) or something similar, see if the solution would work there and then port it to Java.
To answer your question I did something similar by XOR-ing the 'reference' image (no crate in your case) with the current image then either work on the histogram (clustered pixels at right means large difference) or just sum the visible pixels and compare them with a threshold. XOR is not really precise but it is fast.
My point is, it took me 2hrs to install Scilab and the toolkits and write a proof of concept. It would have taken me two days in Java and if the first solution didn't work each additional algorithm (already done in Mat-/Scilab) another few hours. IMHO you are approaching the problem from the wrong angle.
If really Java/C++ are just some simple tools that don't matter then drop them and use Scilab or some other Matlab clone - prototyping and fine tuning would be much faster.
There are 2 parts involved in object detection. One is feature extraction, the other is similarity calculation. Some obvious features of the crate are geometry, edge, texture, etc...
So you can find some algorithms to extract these features from your crate image. Then comparing these features with your training sample images.