Obtain shape data from 3D extracted region in MATLAB - matlab

I am attempting to isolate the shape of a cow in an image. The image is captured using a modified kinect camera. Below is the stage I have got to so far, showing what is left after I have deleted all non-required parts of the image. (The image shows the torso of a cow, viewed from above with the head of the animal on the left).
This was done by deleting all the pixels that were furthest away from the camera (the floor) and then isolating the region that can be seen below.
I am struggling to obtain useful data about this shape. Ideally, I would like to obtain the perimeter, area and major axis. If anyone can help I would be very grateful.
The end goal is to be able to detect a 'cow shape' and then I can move onto the next phase which is to ID each animal.

Related

segmenting an object from background using MATLAB based on feature points

I am working on image segmentation on a gray scale image using MATLAB. At present we have detected few edge points, which when joined together approximate to the shape of the object being detected.
I need the help in separating out only the object from the whole image. The background, i.e. the non-object area can be made fully black or white.
Please give me some hints on where to start.
It is possible to join each point with a line. How to translate the information in terms of those lines in classifying each pixel as belonging to object or background?
An example image of lungs is shown here, where the Left lung is the object and is retained as it is. The background is completely black.
You are looking for the function poly2mask. Try
help poly2mask
An example use case:
t=linspace(0,2*pi,100);
a=(cos(t*3)+2)*20;
x=a.*cos(t)+60;
y=a.*sin(t)+60;
bw = poly2mask(x,y,120,120);

Marching cube for Kinect Fusion- Shadow effect

I am doing with the Kinect Fusion and after I got the TSDF volume (450x450x150), I applied the marching cube (isosurface in MATLAB) to display the 3D mesh. However, what I got is shown the the figure. It had long shadow behind the object. So could you tell me what is wrong with my implementation?
(https://i.stack.imgur.com/onaFX.png)
Thank you very much.
If you could provide you Matlab code, it would be great.
I would; however; like to point out that the shadow is because you only have a single depth frame, with values ranging from 0 (no depth data) to the actual data. When constructing the 3D mesh, the surface is created between adjoining points so along the edges of the object it goes from 0 to the actual depth data thereby creating the 'shadows'. There is no workaround for this. Only if you have a 360 degree data and are creating surfaces in 360degrees then you would get a complete figure. with a complete back and front.

Restoring the image of a face's plane

I am using an API to analyze faces in Matlab, where I get for each picture a 3X3 rotation matrix of the face's orientation, telling which direction the head is pointing.
I am trying to normalize the image according to that matrix, so that it will be distorted to get the image of the face's plane. This is something like 'undoing' the projection of the face to the camera plane. For example, if the head is directed a little to the left, it will stretch the left side to (more or less) preserve the face's original proportions.
Tried using 'affine2d' and 'projective2d' with 'imwarp', but it didn't achieve that goal
Achieving your goal with simple tools like affine transformations seems impossible to me since a face is hardly a flat surface. An extreme example: Imagine the camera recording a profile view of someone's head. How are you going to reconstruct the missing half of the face?
There have been successful attempts to change the orientation of faces in images and real-time video, but the methods used are quite complex:
[We] propose a gaze correction method that needs just a
single webcam. We apply recent shape deformation techniques
to generate a 3D face model that matches the user’s face. We
then render a gaze-corrected version of this face model and
seamlessly insert it into the original image.
(Giger et al., https://graphics.ethz.ch/Downloads/Publications/Papers/2014/Gig14a/Gig14a.pdf)

How to track the center point of the moving feature in the given picture (preferably using MATLAB)?

Suggest a method/algorithm to track the center point of the feature,
the features is part of a video. As the video is played, the feature keeps moving around but never goes out of the rectangle of size shown in figure.
I wish to track the center point over the duration of the video.
*the red point is not part of the image. I have overlaid it to show the center point I wish to track.
A very simple way:
create an image with the pattern to recognize
do cross-correlation along X and Y with your frames
select the peaks of the X and Y correlation signals to identify position
There must be a lot of material around .. start here http://en.wikipedia.org/wiki/Video_tracking
Try using vision.PointTracker in the Computer Vision System Toolbox.

MATLAB image processing of small circles

I have an image which looks like this:
I have a task in which I should circle all the bottles around their opening. I created a simple algorithm and started working it. My algorithm follows:
Threshold the original image
Do some morphological opening in it
Fill the empty holes
Separate the portion of the image using region props such that only the area equivalent to the mouth of the bottles is selected.
Find the centroid for each and draw circle around each bottle.
I did according to the algorithm above and but I have some portion of the image around which I draw a circle. This is because I have selected the area since the area of the mouth of bottle and the remained noise is almost same. And so I yielded a figure like this.
The processing applied on the image look like this:
And my final image after plotting the circle over the original image is like this:
I think I can deal with the extra circle, that is, because of some white portion of the image remained as shown in the figure 2 below. This can be filtered out using regionproping for eccentricity. Is that a good idea or there are some other approaches to this? How would I deal with other bottles behind the glass and select them?
Nice example images you provide for your question!
One thing you can use to detect the remaining bottles (if there are any) is the well defined structure of the placement of the bottles.
The 4 by 5 grid of the bottle should be relatively easy to locate, and when the grid is located you can test if a bottle is detected at each expected bottle location.
With respect to the extra detected bottle, you can use shape features like
eccentricity,
the first Hu moment
a ratio between the perimeter length squared over the area (which is minimized for a circle) details here
If you are able to detect the grid, it should be easy to located it as an outlier (far from an expected bottle location) and discard accordingly.
Good luck with your project!
I've used the same approach as midtiby's third suggestion using the ratio between area and perimeter called shape factor:
4π * Area /perimeter^2
to detect circles from a contour traced image (from the thresholded image) to great success;
http://www.empix.com/NE%20HELP/functions/glossary/morphometric_param.htm
Regarding the 4 unfound bottles, this is rather tricky without some a priori knowledge of what it is you're looking at (as discussed using the 4 x 5 grid, then looking from the centre of each cell). I did think that from the list of contours, most would be of the bottle tops (which you can test using the shape factor stuff), however, one would be of a large rectangle. If you could find the extremities of the rectangle (from the largest contour in terms of area), then remove it from the third image, you'd be left with partial circles. If you then contour traced those partial circles and used a mixture of shape factor/curve detection etc. may help? And yes, good luck again!