Image filter to separate ricegrains - matlab

I am trying to solve an image filtering issue with MATLAB 2013a. Here are two images on which I am trying to work.
My aim is to obtain each rice grain as a separate image.
Following is the process I used and was successful for the first image.
Convert to gray scale,
Obtain grey threshold,
Convert to binary,
Perform dilation and erosion for more accurate filtering,
Use connected component analysis with bwconncomp,
Save each component.
Now if I try to achieve similar binary image for image2, all the rice grain connected to each other comes as a single component.
I have tried to derive edge map with 'canny' or any other like 'sobel', its not working.
Can someone please guide me to achieve this.

Related

Aligning two images

I have two images of the same shoe sole, one taken with a scanning machine and another with a digital camera. I want to scale one of the images so that it can be easily aligned with the other without having to do it all by hand.
My thought was to use edge detection, connect all the points on the outside of the shoe, scale one image to fit right inside the other, and then scale the original image at the same rate.
I've messed around using different tools in the Image Processing toolbox in MatLab, but am making no progress.
Is there a better way to go about this?
My advise would be to firstly use the function activecontour to obtain the outer contour of the shoe on both images. Then use the function procrustes with the binary images as input.
[~, CameraFittedToScan] = procrustes(Scan,Camera);
This transforms the camera image to best fit with the scanned image. If the scan and camera are not the same size then this needs to be adjusted first using the function imresize.

How to get the area of the bubble in the image using MATLAB?

Here are some images taken from experiments which show a bubble caused by spheres moving in liquid.
Now I want to get the area of the bubble from every image using Matlab. The first thing come to my mind is edge detection. So I tried using the following code:
A = imread('D:\1.jpg');
BW1 = edge(A,'sobel');
figure, imshow(BW1)
to get the cavity edge of the picture which was then cropped manually, as the picture show, the result (below) doesn't satisfy requirements. Also, I still don't know how to get the area of the bubble.
So, can someone tell me what should I do?
I think you should use background subtraction and try a simple segmentation.
You could use regionprops to get the area of the bubble:
https://www.mathworks.com/help/images/ref/regionprops.html
I feel like it should work pretty well. If you have a hard time obtaining a clean segmentation you could probably improve the experimental setup to increase the contrast of the bubble with respect to the background by choosing a background as dark as possible and using some lateral illumination to leverage the diffusion of the light by the bubble.
Finally the segmentation should be performed in a region of interest (ROI) since you know the bubble is confined within the tank
As for the issue of getting an accurate cavity edges, the computer vision system toolbox has the vision.ForegroundDetector object, which implements a variant of Stauffer and Grimson's GMM background subtraction. The implementation is very fast, leveraging multiple cores. Check out this example of how to use background subtraction.
As for the issue of finding the area of the bubble, use the bwarea command. https://www.mathworks.com/help/images/ref/bwarea.html, it will sum up all the white pixels in the image.
I believe background subtraction is the most efficient method to calculate this bubble area. Note that you may need to use opening and closing techniques afterwards to filter other regions see (imopen imclose) at: https://uk.mathworks.com/help/images/ref/imopen.html , and afterwards, you can apply bwarea to calculate area. You could also use impixelinfo command to compare intensity level of bubbles and other areas, and therefore, threshold image to extract bubbles. It works only when you have same threshold level for all images. Further, it is possible to combine all these techniques which is completely depended on your images to achieve better results.
Other shape-based techniques also can be used to extract bubble region area.

Fit two binary images (panorama?)

I have several binary images which represent a partial map of an area (~4m radius) and were taken ~0.2m apart, for example:
(Sorry for the different axis limit).
If you look closely, you'll see that the first image is about 20cm to the right.
I want to be able to create a map of the area from several pictures like this.
I've tried several methods, such as Matlab's register but couldn't find any good algorithm for this purpose. Any ideas on how to approach this?
Thanks in advance!
Two possible routes:
Use imregister. This does registration based on image intensity. You will probably want a rigid transform.
However, this will require your data to be an image (matrix), which it doesn't look like it currently is.
Alternatively, you can use control points. These are common (labelled) points in each image which provide a reference to determine the transform.
Matlab has a built in function to determine control points, cpselect. However, again this requires image data. You may be better of writing your own function to do this or just selecting control points manually.
Once you have control points you can determine the transform between them using fitgeotrans

Matlab - Center of mass of object having only its edge

I'm trying to make an object recognition program using a k-NN classifier. I've got a bunch of images for the training part of the classifier and a bunch of images to recognize. Those images are in grayscale and there's an object per image. The problem is that there's only the edge of the object (not filled), so I don't think using regionprops(img,'centroid') will work properly for what I understand...
So how can I get their center of mass?
xenoclast's answer should be quite clear, just to add something extra.
As you are done creating the binary image from the grayscale image of yours using im2bw; if the edge of your the object is a the boundary that covers the object fully, you may use regionprops(bw,'centroid') directly without going through imfill.
The first step would be to binarise the image with im2bw. Then you can use imfill(img, 'holes') to turn it from an outline into a filled solid. After that regionprops will work as expected.

Detecting shape from the predefined shape and cropping the background

I have several images of the pugmark with lots of irrevelant background region. I cannot do intensity based algorithms to seperate background from the foreground.
I have tried several methods. one of them is detecting object in Homogeneous Intensity image
but this is not working with rough texture images like
http://img803.imageshack.us/img803/4654/p1030076b.jpg
http://imageshack.us/a/img802/5982/cub1.jpg
http://imageshack.us/a/img42/6530/cub2.jpg
Their could be three possible methods :
1) if i can reduce the roughness factor of the image and obtain the more smoother texture i.e more flat surface.
2) if i could detect the pugmark like shape in these images by defining rough pugmark shape in the database and then removing the background to obtain image like http://i.imgur.com/W0MFYmQ.png
3) if i could detect the regions with depth and separating them from the background based on difference in their depths.
please tell if any of these methods would work and if yes then how to implement them.
I have a hunch that this problem could benefit from using polynomial texture maps.
See here: http://www.hpl.hp.com/research/ptm/
You might want to consider top-down information in the process. See, for example, this work.
Looks like you're close enough from the pugmark, so I think that you should be able to detect pugmarks using Viola Jones algorithm. Maybe a PCA-like algorithm such as Eigenface would work too, even if you're not trying to recognize a particular pugmark it still can be used to tell whether or not there is a pugmark in the image.
Have you tried edge detection on your image ? I guess it should be possible to finetune Canny edge detector thresholds in order to get rid of the noise (if it's not good enough, low pass filter your image first), then do shape recognition on what remains (you would then be in the field of geometric feature learning and structural matching) Viola Jones and possibly PCA-like algorithm would be my first try though.