|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <ec52bdcb-45e0-4ed5-bbe8-4267a4f43558@e28g2000vbd.googlegroups.com>...
> On May 21, 2:08 pm, "Emre " <jasonb...@windowslive.com> wrote:
> > Hi,
> > I'm working on a project to detect ships at horizon.
> > But, first I have to detect horizon and then work on object above the horizon.
> > I'd be glad to receive any help.
>
> ----------------------------------------------------------------
> Post some images. Presumably this is just a student project because
> in these days of radios, telephones, and GPS, I don't see any
> practical use for this. But this means that you'll probably have nice
> photos with ships on the horizon. I've lived on the California coast
> so I know that often (maybe most of the time?) you don't see the ...
First of all I tried to use "canny edge detection" to find edges. Then I used "hough" trasnsform to find the longest horizontal line. And I used this line to draw horizon line.
Then, I used medfilt2 on original image to remove noise.
Next, I used canny edge detection to detect edges
then, I applied conv2 to reduce the number of connected components
after that, I found the connected components with "bwlabel"
then, I used "regionprops" to measure properties of image regions.
Then I wanted to eliminate the parts that have below the area of 500 pixel
finally, I wanted to get the regions match to this criteria in "boundingBox"
When I erase the pixels near the horizon when not erasing this pixels multiple regions perceive as one connected component because of the horizon line..(But, I'm not sure that erasing pixels below horizon is the correct approach).
When there is nothing except the ship or land above horizon I can take them in a box
But, when there is land behind the ship I can't discriminate the ship and binary image gets too complex. Even if I can find an object on the surface how can I know whether it's a ship or land.
I will be very grateful if you or anyone can help.(I'm in a great stress because of the possibility of not being able to finish the project on time)
Here is the source code I've written so far. The links for the pictures are below the source code.
%detection.m
A = imread('im2.jpg');
R = imresize(A, [333 500]);
I = rgb2gray(R);
BW = edge(I, 'canny', 0.1);
%hough transform to find the lines
[H, T, R] = hough(BW);
P = houghpeaks(H, 5, 'threshold', ceil(0.3*max(H(:))));
x = T(P(:,2));
y = R(P(:,1));
lines = houghlines(BW,T,R,P,'FillGap',4,'MinLength',7);
figure, imshow(I), hold on
max_len = 0;
for k=1:length(lines)
xy = [lines(k).point1; lines(k).point2];
%Find the length of each line
len = norm(lines(k).point1 - lines(k).point2);
if (len > max_len)
%change the value of max_len when finding a
%longer line
max_len = len;
%find the longest line at most that has 0.1 degree
%because I thought the horizon should be straight
if (atan((xy(2,2)-xy(1,2))/(xy(2,1)-xy(1,1)))<0.1...
&& atan((xy(2,2)-xy(1,2))/(xy(2,1)-xy(1,1)))...
> -0.1 && (xy(2,2)>150))
xy_long = xy;
end
end
end
%draw the longest line from one side of the picture
%to other side
xy_long(1,1) = 0;
xy_long(2,1) = 500;
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan');
%------------------------------------
%Median filtering the image to remove noise
im1=medfilt2(I,[3 3]);
BW1 = edge(im1,'canny',0.4); %finding edges
[imx,imy]=size(BW1);
msk=[0 0 0 0 0;
1 1 1 1 1;
1 1 1 1 1;
1 1 1 1 1;
0 0 0 0 0;];
%Smoothing image to reduce the number of connected components
BW1=conv2(double(BW1),double(msk));
%erase the pixel values near horizon
%before finding connected components
y_begin = xy_long(1,2)-5;
y_end = xy_long(1,2)+5;
for k = y_begin:y_end
for m = 1 : 500
BW1(k,m) = 0;
end
end
L = bwlabel(BW1,8);% Calculating connected components
%I wanted to find the region properties
stats = regionprops(L,BW1,{'Area','BoundingBox'});
%find areas more than 500 pixels
idx = find([stats.Area]>400);
for k=1:length(idx)
%find the regions above horizon
if(stats(idx(k)).BoundingBox(2) < xy_long(1,2))
rectangle('Position',stats(idx(k)).BoundingBox,...
'EdgeColor','y');
end
end
hold off
figure, imshow(BW1)
%*********************
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im10.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im8.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im2.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im7.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im12.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im5.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im9.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im6.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im1.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im4.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im3.jpg
http://i804.photobucket.com/albums/yy326/lifesgood_photos/im11.jpg
|