Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Haar wavelet to detect LINES on an image?

So I have an image like this:

 CG generated bathroom

I want to get something like this (I haven't drawn all lines I want but I hope you can get my idea):

 Black & White CG generated bathroom with some red lines  between tiles

I want to use SURF ( (Speeded Up Robust Features) is a robust image descriptor, first presented by Herbert Bay et al. in 2006 ) or something that is based on sums of 2D Haar wavelet responses and makes an efficient use of integral images for finding all straight lines on image. I want to get relative to picture pixel coords start and end points of lines.

So on this picture to find all lines between tiles and those 2 black lines on top.

Is there any such Code Example (with lines search capability) to start from?

I love C and C++ but any other readable code will probably work for me=)

like image 674
Rella Avatar asked Apr 08 '10 11:04

Rella


People also ask

What is Haar wavelet used for?

Haar wavelet compression is an efficient way to perform both lossless and lossy image compression. It relies on averaging and differencing values in an image matrix to produce a matrix which is sparse or nearly sparse.

What is Haar wavelet transform in image processing?

The Haar transform is the simplest of the wavelet transforms. This transform cross-multiplies a function against the Haar wavelet with various shifts and stretches, like the Fourier transform cross-multiplies a function against a sine wave with two phases and many stretches.

What is the use of Haar transform in image processing?

The Haar transform separates the image into high frequency and low frequency components. The image array is split into two halves containing the transformed data and the detail coefficients.

Why wavelet transform is used in image processing?

Wavelets based transform are mathematical tools which are used to extract information from images [12]. A significant benefit it has over Fourier transforms is temporal resolution which signifies that it can captures both frequency and location information of the images [13].


2 Answers

The following is a complete example of applying Hough Transform to detect lines. I am using MATLAB for the job..

The trick is to divide the image into regions and process each differently; this is because you have different "textures" in your scene (tiles on the upper region of the wall are quite different from the darker ones on the bottom, and processing the image all at once wont be optimal).

As a working example, consider this one:

%# load image, blur it, then find edges
I0  = rgb2gray( imread('http://www.de-viz.ru/catalog/new2/Holm/hvannaya.jpg') );
I = imcrop(I0, [577 156 220 292]);     %# select a region of interest
I = imfilter(I, fspecial('gaussian', [7 7], 1), 'symmetric');
BW = edge(I, 'canny');

%# Hough Transform and show accumulated matrix
[H T R] = hough(BW, 'RhoResolution',2, 'Theta',-90:0.5:89.5);
imshow(imadjust(mat2gray(H)), [], 'XData',T, 'YData',R, ...
       'InitialMagnification','fit')
xlabel('\theta (degrees)'), ylabel('\rho')
axis on, axis normal, colormap(hot), colorbar, hold on

%# detect peaks
P  = houghpeaks(H, 20, 'threshold',ceil(0.5*max(H(:))));
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);

%# detect lines and overlay on top of image
lines = houghlines(BW, T, R, P, 'FillGap',50, 'MinLength',5);
figure, imshow(I), hold on
for k = 1:length(lines)
    xy = [lines(k).point1; lines(k).point2];
    plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off

alt text

alt text

alt text

You could try the same procedure for other regions while tuning the parameters to get good results..

like image 165
Amro Avatar answered Sep 29 '22 06:09

Amro


Have you tried a simpler approach such as the Hough transform for finding lines? A function to perform this and example are included in OpenCV called cvHoughLines2.

like image 42
jeff7 Avatar answered Sep 29 '22 07:09

jeff7