Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, Here is the code I have written for thresholding an image. But its giving the error as illegel if statement use. Can anybody help me to correct it.

clc;
close all;
clear all;
 
I = imread('uma.png');
subplot(3,2,1);
imshow(I);
title('Original');
 
% ------------------Check its size-------------------------------------------------- 
[x y]=size(I)
 
% ----------------Grayed image-----------------------------------------------------
gray = rgb2gray(I);
subplot(3,2,2);imshow(gray);
title('Gray image');
 
% Histogram Plotting
 subplot(3,2,3);imhist(gray,64);
title('Histogram');
 

% Thresholding an image
T=20;
cnt = 0;
x =0;y=0;
for i = 1:1:x+1
    
    for j = 1:1:y+1
        {
            if {gray(i,j)=<t;>
                gray(i,j)=0;
             cnt= cnt+1;
            }
        else{
             gray(i,j)=255;
            }
            end
    end
end
 
        figure; imshow(gray);


OR 

 % Thresholding an image


T =20;
c=zeros(size(gray));
[r c1] = size(gray);
allpix=gray(r, c1);
for i=1:r
    for j=1:c1
if allpix(i,j)> T
    c=255;
else
    c=0;
end
    end
end
figure, imshow(c);
Posted
Updated 1-Nov-14 23:35pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900