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:
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!
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:
The code:
minrad = 20;
maxrad = 110;
Hsens = .93;
[cen, r] = imfindcircles(img, [minrad maxrad],'Sensitivity', Hsens);
And the result:
Interestingly, the result is much better that what your original code does. The simpler the better !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With