Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

% Exercise 2: clear all; im1=imread('countCoins.png'); %im1=double(im1); sum=0; sum1=0; sum2=0; T1=0; T2=0; mean1 = 0; mean2 = 0; R2=im1(:,:,1); G2=im1(:,:,2); B2=im1(:,:,3); for i = 1:size(R2,1)

% Exercise 2:
clear all;
im1=imread('countCoins.png');
%im1=double(im1);
sum=0; sum1=0; sum2=0; T1=0; T2=0; mean1 = 0; mean2 = 0;
R2=im1(:,:,1);
G2=im1(:,:,2);
B2=im1(:,:,3);
for i = 1:size(R2,1)
for k = 1:size(R2,2)
I3(i,k)= 0.299 * R2(i,k) + 0.587 * G2(i,k) + 0.114 * B2(i,k);
end
end
imwrite(I3,'GS.jpg');
%I3=double(I3)
% figure(1)
% imshow(I3)
for i = 1:size(I3,1)
for k = 1:size(I3,2)
sum=sum+double(I3(i,k));
end
end
T1 =(sum)/(size(I3,1)*size(I3,2))
limit=1;
T2 = T1+limit+1;
while(abs(T2 - T1) > limit)
T1 = T2;
fore=0; back=0;
for i = 1:size(I3,1)
for k = 1:size(I3,2)
if(I3(i,k)> T2)
fore=fore+1;
sum1=sum1+double(I3(i,k));
else
back=back+1;
sum2=sum2+double(I3(i,k));
end
end
end
mean1=(sum1)/(fore);
mean2=(sum2)/(back);
T2 = (mean1 + mean2) / 2;
end
%
for i = 1:size(I3,1)
for k = 1:size(I3,2)
if(I3(i,k)> T2)
im2(i,k)=255;
else
im2(i,k)=0;
end
end
end
imwrite(im2,'countcoinsBW.jpg');
img3 = imfill(im2,'holes');
[B,L,n,A] = bwboundaries(im2);
NumberOfCoins = n
image text in transcribed
image text in transcribed
here is my code for this problem and the question is the first picture. The second picture is lecture notes if that helps... it is supposed to use automatic thresholding and then determine the number of coins in the picture.... I cannot get it to work and im pretty sure my main error is somewhere in the while loop... can you help with me it?
Exercise 2 Count the number of objects using the same image as in Ex. 1 using your own functions to convert the RGB image to grayscale and from grayscale to black & white (use your own Automatic Thresholding method to select the optimal threshold value that will convert it to black & white). Then, use MATLAB's built-in functions imfill and bwboundaries to count the number of coins Image Binarization: Automatic Thresholding Automatic thresholding is a great way to extract useful information encoded into pixels while minimizing background noise. This is accomplished by utilizing a feedback loop to optimize the threshold value before converting the original grayscale image to binary. The Idea is to separate the image into two parts; the background and foreground 1. Select initial threshold value, typically the mean 8-bit value of the original image 2. Divide the original image into two portions; - Pixel values that are less than or equal to the threshold; background -Pixel values greater than the threshold; foreground 3. Find the average mean values of the two new images 4. Calculate the new threshold by averaging the two means, 5. If the difference between the previous threshold value and the new threshold value are below a specified limit, you are finished. Otherwise apply the new threshold to the original image keep trying. Exercise 2 Count the number of objects using the same image as in Ex. 1 using your own functions to convert the RGB image to grayscale and from grayscale to black & white (use your own Automatic Thresholding method to select the optimal threshold value that will convert it to black & white). Then, use MATLAB's built-in functions imfill and bwboundaries to count the number of coins Image Binarization: Automatic Thresholding Automatic thresholding is a great way to extract useful information encoded into pixels while minimizing background noise. This is accomplished by utilizing a feedback loop to optimize the threshold value before converting the original grayscale image to binary. The Idea is to separate the image into two parts; the background and foreground 1. Select initial threshold value, typically the mean 8-bit value of the original image 2. Divide the original image into two portions; - Pixel values that are less than or equal to the threshold; background -Pixel values greater than the threshold; foreground 3. Find the average mean values of the two new images 4. Calculate the new threshold by averaging the two means, 5. If the difference between the previous threshold value and the new threshold value are below a specified limit, you are finished. Otherwise apply the new threshold to the original image keep trying

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions