QuestionQuestion

Detecting Arbitrary Shape in an Image using Hough Transformation,
Sample program with image input and target image needed.
Comment enough on the code so that report can be made out of it.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function detect_object(image,scene,to_plot)
% INPUTS
% image - a square rgb image containing the main object
% scene - a square rgb image containing a set of objects
% The goal of the algorithm is to detect the main object in the scene.

if nargin < 3
    to_plot=0;
end

%make the image into a gray image
image=rgb2gray(image);

%Extract the edges. For the image given
%to make a logical image based on if the pixel
%values exceed 160 or not gives very clear edges
%and produces simpler edges than the 'canny' algorithm

edges_image=(image<160);%edge(image,'canny');
figure
imshow(edges_image)
title('Edges in the image');

%This is for plotting information only and shows what the Hough
%transform extracts out of the input image.
%This is standard Matlab sample code for the Hough transform.
if to_plot
    [Hi,Ti,Ri]=hough(edges_image);
    figure, imshow(imadjust(mat2gray(Hi)),[],'XData',Ti,'YData',Ri,...
            'InitialMagnification','fit');
    xlabel('\theta (degrees)'), ylabel('\rho');
    axis on, axis normal, hold on;
    colormap(hot)
    title('image');
    Pi = houghpeaks(Hi,15,'threshold',ceil(0.3*max(Hi(:))));
    xi = Ti(Pi(:,2));
    yi = Ri(Pi(:,1));
    hold on
    plot(xi,yi,'s','color','black');
    lines = houghlines(edges_image,Ti,Ri,Pi,'FillGap',5,'MinLength',7);
    figure;
    imshow(edges_image);
    max_len=0;
    hold on
    for k = 1:length(lines)
       xy = [lines(k).point1; lines(k).point2];
       plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

       % Plot beginnings and ends of lines
       plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
       plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

       % Determine the endpoints of the longest line segment
       len = norm(lines(k).point1 - lines(k).point2);
       if ( len > max_len)
            max_len = len;
            xy_long = xy;
       end
    end
end...
$15.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Image Processing Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats