Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Open the script next given In this script you have the main necessary commands, except for the highlighted with blue colour. Make sure

1. Open the script next given In this script you have the main necessary commands, except for the highlighted with blue colour. Make sure you have the input images: sample.jpg,
2. Convert the image in binary format, using im2bw. You should find the appropriate threshold value, so that the binarisation operation applies to all objects from the input image. Include the results of the binarisation of one of the images and the value of the threshold value in your report.
3. Find the connected components of your obtained binary images (with bwlabel ) and visualise (with label2rgb) the detected connected components.You have this functionality in the provided script. You do not need to include this visualisation in your report.
4. Compute different characteristics of the connected components (with regionprops). Visualise the bounding boxes of the objects (BoundingBox field from the regionprops function output, rectangle(Position,)). You have this functionality in the provided script. It is not required to include this visualisation in your report.
5. Develop a function to distinguish arrows from other objects. What does differ the arrows from the other objects? You may use any ideas from lectures, the previous lab session or common sense for your function. Include the brief description of main idea of your function in your report and the actual code of the function in the appendix of your report. Hint: arrows have points of different colour.
6. Find the starting red arrow. You have this functionality in the provided script.
7. Develop a function to find the label of the next nearest object to which the current arrow indicates.
Hint 1: to set a line it is enough to have two points.
Hint 2: for each arrow you may extract the centroid point and the yellow one.
Hint 3: a vector (x2 x1, y2 y1) points to the direction from the point (x1, y1) to the point (x2, y2).
8. Apply your functions to find the treasure in the images. Visualise the treasure and the path to it from the starting arrow. You have this functionality in the provided script. Include your visualisation in your report for all images.
9. Other solutions of this task are possible. If you propose a different solution, include a brief description of it and provide a diagram of the main idea of your solution. Include your functions in your report.
close all;
clear all;
%% Reading image
im = imread('Treasure_simple.jpg'); % change name to process other images
imshow(im); pause;
%% Binarisation
bin_threshold =0; % parameter to vary
bin_im = im2bw(im, bin_threshold);
imshow(bin_im); pause;
%% Extracting connected components
con_com = bwlabel(bin_im);
imshow(label2rgb(con_com)); pause;
%% Computing objects properties
props = regionprops(con_com);
%% Drawing bounding boxes
n_objects = numel(props);
imshow(im);
hold on;
for object_id =1 : n_objects
rectangle('Position', props(object_id).BoundingBox, 'EdgeColor', 'b');
end
hold off; pause;
%% Arrow/non-arrow determination
% You should develop a function arrow_finder, which returns the IDs of the arror objects.
% IDs are from the connected component analysis order. You may use any parameters for your function.
arrow_ind = arrow_finder();
%% Finding red arrow
n_arrows = numel(arrow_ind);
start_arrow_id =0;
% check each arrow until find the red one
for arrow_num =1 : n_arrows
object_id = arrow_ind(arrow_num); % determine the arrow id
% extract colour of the centroid point of the current arrow
centroid_colour = im(round(props(object_id).Centroid(2)), round(props(object_id).Centroid(1)), :);
if centroid_colour(:, :,1)>240 && centroid_colour(:, :,2)<10 && centroid_colour(:, :,3)<10
% the centroid point is red, memorise its id and break the loop
start_arrow_id = object_id;
break;
end
end
%% Hunting
cur_object = start_arrow_id; % start from the red arrow
path = cur_object;
% while the current object is an arrow, continue to search
while ismember(cur_object, arrow_ind)
% You should develop a function next_object_finder, which returns
% the ID of the nearest object, which is pointed at by the current
% arrow. You may use any other parameters for your function.
cur_object = next_object_finder(cur_object);
path(end +1)= cur_object;
end
%% visualisation of the path
imshow(im);
hold on;
for path_element =1 : numel(path)-1
object_id = path(path_element); % determine the object id
rectangle('Position', props(object_id).BoundingBox, 'EdgeColor', 'y');
str = num2str(path_element);
text(props(object_id).BoundingBox(1), props(object_id).BoundingBox(2), str, 'Color', 'r', 'FontWeight', 'bold', 'FontSize', 14);
end
% visualisation of the treasure
treasure_id = path(end);
rectangle('Position', props(treasure_id).BoundingBox, 'EdgeColor', 'g');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions