Sunday, March 27, 2016

Gray Level Slicing in MATLAB

 Gray Level Slicing: High-light specific range of gray values without background and with background.

       Read kidney.tif file. Enter lower and upper threshold value from the user. Apply gray level slicing with and without background. Display the result.

 CODE:
clc; clear all;

i=imread('kidney.tif');          % should be graylevel image
j=double(i);
k=double(i);
[row,col]=size(j);
T1=input('Enter the Lowest threshold value:');
T2=input('Enter the Highest threshold value:');
for x=1:row            
    for y=1:col        
        if((j(x,y)>T1) && (j(x,y)<T2))
            j(x,y)=i(x,y);
            k(x,y)=255;
        else
            j(x,y)=0;
            k(x,y)=0;
        end
    end
end

subplot(311), imshow(i), title('Original image')   
subplot(312), imshow(uint8(j)), title('Graylevel slicing with background')
subplot(313), imshow(uint8(k)), title('Graylevel slicing without background')

OUTPUT RESULT:

5 comments:

  1. Please tell us what values to enter in input as lower and upper threshold value.

    ReplyDelete
    Replies
    1. just enter random value for test between 1 to 255

      Delete
  2. Please tell us what values to enter in input as lower and upper threshold value

    ReplyDelete