



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




clear all clc I = imread('elephant.tif'); k=1; for Th = 150:250; f_xy = I; f_xy(I<Th) = 1; f_xy(I>=Th)= 0; ElephantArea (k) = sum(sum(f_xy))/(289*417); k=k+1; end plot(150:250,ElephantArea3)
150 160 170 180 190 200 210 220 230 240 250
1
Threshold
Area of elephant
% This program estimates the area of the elephant.tif % I(f), using three approaches: % 1- nested calls to quad % 2- dblquad % 3- summation over the function f(x,y) % f(x,y) = 1 if (x; y) is inside the elephant % = 0 otherwise. % % Written by Sima Taheri % Date: 10/12/ % % Input : -- % Output: I_f: Estimates area of elephant by three methods % t : Elapsed time for each estimation
clc close all clear all
% Load the elephant picture stored in elephant.tif % and define it as a global variable global I I = imread('elephant.tif');
% Measure cost time using tic and toc % 1- nested calls to quad tic q1 = quad (@g,1,289); ElephantArea1 = q1/(289*417); t1 = toc;
% Define function f(x,y) for dblquad function t = f(x,y) global I
Th = 200;
t = zeros(1,length(y)); for i=1:length(x) if I(round(x(i)),round(y)) < Th t(i) = 1; else t(i)=0; end end
Area of the elephant and the elapsed time for three different methods
Tol = 1e-6 Nested quad 5.217e-001 3.178e+ Tol = 1e-7 & Nested quad 5.386e-001 4.717e+ 1e-
Dblquad 5.627e-001 2.777e+
Summation 5.593e-001 8.608e-