## Question

Sample program with image input and target image needed.

Comment enough on the code so that report can be made out of it.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use 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...

By purchasing this solution you'll be able to access the following files:

Solution.zip.