Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
detecting ships at horizon

Subject: detecting ships at horizon

From: Emre

Date: 21 May, 2010 18:08:05

Message: 1 of 8

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.

Subject: detecting ships at horizon

From: Mark Shore

Date: 21 May, 2010 18:18:05

Message: 2 of 8

"Emre " <jasonborn@windowslive.com> wrote in message <ht6i65$bko$1@fred.mathworks.com>...
> 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.

Google it, or work it out from scratch. Only simple trigonometry is required and it will be trivial to implement in MATLAB.

Subject: detecting ships at horizon

From: Doug Hull

Date: 21 May, 2010 18:19:05

Message: 3 of 8

"Emre " <jasonborn@windowslive.com> wrote in message <ht6i65$bko$1@fred.mathworks.com>...
> 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.

What kind of sensors? Do you have typical (assuming) images with and without ships present? What have you tried?

Subject: detecting ships at horizon

From: ImageAnalyst

Date: 21 May, 2010 18:54:02

Message: 4 of 8

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
horizon. I know that seeing a sun sink below the horizon is a fairly
scarce event - most of the time the sun sinks into the "marine
layer" (which is a layer of fog above the ocean) and fades away, much
to the displeasure of visiting tourists, although you can see the
horizon sometimes during the middle of the day when the marine layer
has retracted from the coast. But you'll probably have a set of nice,
perfect sample images with clearly distinct sky, water, and ship,
where you just have to find the top rectangular region and the bottom
rectangular region, using texture, color, etc. and then find the
horizon line. Maybe you'll use edge filters also, or maybe you'll use
a combination of things.
Good luck.

Subject: detecting ships at horizon

From: Emre

Date: 22 May, 2010 15:16:03

Message: 5 of 8

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

Subject: detecting ships at horizon

From: ImageAnalyst

Date: 22 May, 2010 19:52:55

Message: 6 of 8

You know what? NO ONE is going to finish this project on time. Some
of these images are just too challenging. You'd need a lot higher
level of knowledge than any short class assignment. How is a simple
algorithm going to know the difference between a ship with a bunch of
towers and the cityscape behind it? It won't, unless you build a lot
of real world knowledge into it and that's not easy. It might be
easier if they were videos and moved with respect to the camera and
the rest of the scene. But I seriously seriously doubt anyone in your
class will have every ship in every image automatically outlined any
time soon. Maybe your professor is just trying to see what kinds of
creative ways the students try. You did a passable job with that,
although there could be more things you could demonstrate, and I'm not
sure I know what "conv2 to reduce the number of connected components"
is all about. But I think your professor will give an "A" for effort
and not expect anyone to solve every photo. So just make additional
effort with some more filters and you should get a good grade.

Subject: detecting ships at horizon

From: Mark Shore

Date: 22 May, 2010 20:23:04

Message: 7 of 8

"Mark Shore" <mshore@magmageosciences.ca> wrote in message <ht6iot$k1g$1@fred.mathworks.com>...
> "Emre " <jasonborn@windowslive.com> wrote in message <ht6i65$bko$1@fred.mathworks.com>...
> > 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.
>
> Google it, or work it out from scratch. Only simple trigonometry is required and it will be trivial to implement in MATLAB.

Never mind this comment. From your first post I assumed you were referring to the classic problem calculating the distance to an object of height A from a viewpoint of height B, with the line of sight tangent to the Earth's surface. As far as your much different project goes, ImageAnalyst has said more than I could.

Subject: detecting ships at horizon

From: ImageAnalyst

Date: 22 May, 2010 21:14:23

Message: 8 of 8

On May 22, 4:23 pm, "Mark Shore" <msh...@magmageosciences.ca> wrote:
> Never mind this comment. From your first post I assumed .....

------------------------------------------
Just goes to show you how much time and effort would be saved if
people would only post their images FIRST. It happens all the time so
I shouldn't be surprised, but I always am at people who ask how to
process and image without showing people the image.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us