Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find timber in a truck using MATLAB?

My problem is to find and count timber in the truck automatically using image with the back of the trailer. Im trying to solve this problem using MATLAB Image Toolbox. So, here is my code.

function [ centers, rads, metrics ] = TimberFind( img )
    minrad = 20;
    maxrad = 110;
    Hsens = .93;
    CannySens = .20;

    img_gray = rgb2gray(img);
    PSF = fspecial('gaussian', 5, 0.5);
    img_gray = imfilter(img_gray, PSF, 'symmetric', 'conv');
    img_gray = imadjust(img_gray);
    PSF=fspecial('gaussian', 10, 1);
    Blurred = imfilter(img_gray, PSF, 'symmetric', 'conv');
    cont = imsubtract(img_gray, Blurred);
    preprocessed = imadd(img_gray, 3*cont);    

    bin = edge(preprocessed, 'canny', CannySens);

    [cen, r, m] = imfindcircles(bin, [minrad maxrad],'Sensitivity', Hsens);  
end

But the result is not very good. You can see the full data set or the following example: first input imagefirst output image

So, if I make Canny and imfindcircles algorithms sensetive enough to detect all timber, there are some excess resoults found. I have an idea to solve this problem with cutting out each timber from the big image, then constucting some global criteria of obtained small pictures, and try some machine learning algorithm on it. But I think this way is rather difficult, so maybe somebody could suggest anything else? Maybe there is a better way to make preprocessing of the image before using Canny operator? If you have any idea how to make it better, please tell me. Thanks!

like image 382
Vladimir Avatar asked Apr 19 '15 18:04

Vladimir


1 Answers

Actually there is not really a need to preprocess your images, i.e. neither going grayscale, Gaussian filtering nor Cany edge detection are actually useful before using imfindcircles.

A simplified version of your code gives a very decent result on this image:

enter image description here

The code:

minrad = 20;
maxrad = 110;
Hsens = .93;

[cen, r] = imfindcircles(img, [minrad maxrad],'Sensitivity', Hsens);

And the result:

enter image description here

Interestingly, the result is much better that what your original code does. The simpler the better !

like image 118
Ratbert Avatar answered Nov 06 '22 14:11

Ratbert