Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created September 4, 2020 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehzawad/19ddb3b11d5844b41cc779e72f1f1328 to your computer and use it in GitHub Desktop.
Save ehzawad/19ddb3b11d5844b41cc779e72f1f1328 to your computer and use it in GitHub Desktop.
clc
clear all
close all
I = imread('/Users/ehzawad/Desktop/footBall_orig.jpg');
% I = imread('peppers.png');
Im = rgb2gray(I);
% disp(Im);
% I = imread('bag.png');
%
% figure, subplot(2,2,1), imshow(I), title('Original Image');
% [I_prw1,t1] = edge(I,'Canny'); % % sobel prewitt Roberts log zerocross Canny
% subplot(2,2,2), imshow(I_prw1);
% I_noise = imnoise(I,'gaussian');
% % [I_prw2,t2] = edge(I_noise,'Canny'); % sobel prewitt Roberts log zerocross Canny
% [I_prw2,t2] = edge(I_noise,'Canny', [], 2.5); % sobel prewitt Roberts log zerocross Canny
% subplot(2,2,3), imshow(I_noise);
% subplot(2,2,4), imshow(I_prw2);
th = .50;
% I_bw = im2bw(I,.5);
% I_bw = imbinarize(I, 0.5);
% iteration = 1000;
flattenImage = Im(:);
% disp(flattenImage);
% iteration = length(I_bw);
for i = 1 : iteration
%first segment or piece
disp(th);
G1 = flattenImage > th;
disp(G1);
G2 = flattenImage <= th;
disp(G2);
median = (mean(G1) + mean(G2))/ 2;
% disp(median);
if (abs(median - th) <= 0.001)
break
end
th = median;
% disp(th);
end
newEstimated = im2bw(I, th);
imshow(newEstimated);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment