clc;
close all;
clear all;

a = rgb2gray(a);
subplot(3,3,1);
imshow(a); title('Original Image');

% Simple thresholding at 0.3
% This is equivalent to saying threshoding at pixel value
% 0.3 x 255 = 76.5 , approximatesly 77
% imlabel() is a Matlab command that can threshold any matrix

level = 0.3;
%% Display the threshold image
subplot(3,3,2);
segimage1 = im2bw(a,level);
imshow(segimage1); title('Simple Thresholding at 0.3');

% Simple thresholding at 0.6
% So threshold value is 0.6 x 255 = 153
% Single Thresholding can be done like this also

%% Display the threshold image
subplot(3,3,3);
imshow(a > 153); title('Simple Thresholding at 0.6');

% Multiple thresholding Algorithm
% Let us assume that the output should be zero if pixel value is
% if <= 0.1 x 255 = 25.5 = 26, pixel output 204 if pixel value is <= 0.9 x
% 255 = 230 and 0 if pixel value is above 230.

%% Create a temporary matrix g

tmp = a;

[m n]= find(a<26);
for j = 1: length(m)
tmp(m(j),n(j))=0;
end

[m n]= find(a>26 & a <= 230);
for j = 1: length(m)
tmp(m(j),n(j))=0.8;
end

[m n]= find(a>230);
for j = 1: length(m)
tmp(m(j),n(j))=0;
end
subplot(3,3,4);
segimage2 = im2bw(tmp,0);
imshow(segimage2); title('Multiple threshoding(Between 27-230)');

%% Find the threshold Value using Otsu Algorithm

level = graythresh(a);

%% Display the threshold image

subplot(3,3,5);
segimage = im2bw(a,level);
imshow(segimage); title('Otsu - Optimal Segmented Image');

%% Display Blured Image

subplot(3,3,6);

level = graythresh(b);
subplot(3,3,7);
segimage = im2bw(b,level);
imshow(segimage); title('Otsu - Segmentation for bad illuminated Image');

b = rgb2gray(b);

%Create an average Image

avgfilt = ones(13,13);

%Create an median image
im1 = medfilt2(b,[20 20]);

% threshold = mean + constant (Here 18)

thresh = im+18;
subplot(3,3,8);

%Adaptive threshold algorithm used threshold = mean + constant (Here 2)
thresh1 = im1 + 2;
subplot(3,3,9);

MATLAB CODE - for Image Segmentation Based on Threshold Processing Reviewed by Suresh Bojja on 10/22/2015 01:24:00 AM Rating: 5

## Subjects & Labs

AC (6) ADS (2) ATMEL (6) AWP (5) C- Language (3) CAO (5) CDAC (1) CMC (6) CN (10) Control Sys (2) CVSM (2) DC (5) DIP (17) DLD (10) DS (4) DSD&DICA (9) DSP (6) EDC (45) Embedded (7) EMWTL (6) ENERGY AUDIT (1) Engg.Chemistry (11) Faculty Labs (1) Fuzzy (3) II MID (1) LICA (1) Linux OS (1) Materials (1) MATLAB (27) MCU IDE 8051 (1) MEMS (4) MPMC (57) MTECH (6) MWE (2) OC (1) PDC (9) Projects (8) RADAR (1) Research (9) RVSP (3) SC (1) Softwares (1) SS (1) STLD (18) TCSS (1) TSSN (1) TV Engg (1) VHDL (4) VLSI (8) WCN (1) WSN (2)

Name

Email *

Message *