Wednesday, 5 October 2016

Image Processing - Segmentation



Roipoly


>> mask3=roipoly(f);
>> r=immultiply(mask3,f(:,:,1));
>> g=immultiply(mask3,f(:,:,2));
>> b=immultiply(mask3,f(:,:,3));
>> g3=cat(3,r,g,b);
>> imshow(g3);
>> g3=rgb2gray(g3);
>> plot(g3);


---------------------------------------------------------------------


Threshold 

 

close all
I=imread('D:\redfish.png');
imshow(I);
I1=im2double(I);
I2=mat2gray(I1);
I3=rgb2gray(I);
xx=graythresh(I);
for i= 1 : 5
bw=im2bw(I3,xx);
figure;imshow(bw);
imshow(I(:,:,1)>i & I(:,:,2)>i & I(:,:,3)>i)
end
% fthresholding by giving the range values (inbetween)
[x,map]=imread('D:\sae.png');
% s=uint8(256*ind2gray(x));
s=rgb2gray(x);
for i=10 : 200
figure,imshow(s>i & s<i+25)
end
----------------------------------------------
prog2

b=rgb2gray(a);
for i=10 : 200
figure,imshow(b>i);
% pause(5)
end
--------------------------------
[r,c,val]=find(I(:,:,1)>120)
a=I(:,:,1);

for i=1 : numel(r)

for j= 1 : numel(c)
r1=r(i);c1=c(i);
a1(r1,c1)=a(r1,c1);
end
end
imshow(a1);
-------------------------------------
function c=edgedetection(a,b)
%Edge detection
%==============
%a is a input image
%b is used to user supply a input
disp('Edge detection');
disp('1 -> Sobel');
disp('2 -> Prewitt');
disp('3 -> Roberts');
disp('4 -> Laplacian of a Gaussian');
disp('5 -> Zero crossing');
disp('6 -> Canny');
while b<=6
    b=input('Enter the value :');
    switch b
        case 1
            disp('1 -> Sobel');
            a=imread(
'D:\h3.jpg');
            s=edge(a,'sobel')
            imshow(s);
        case 2
            disp('2 -> Prewitt');
            a=imread(
'D:\h3.jpg');
            s=edge(a,'prewitt')
            imshow(s);
        case 3
            disp('3 -> Roberts');
            a=imread(
'D:\h3.jpg');
            s=edge(a,'Roberts')
            imshow(s);
         case 4
             disp('4 -> Laplacian of a Gaussian');
            a=imread('C:\MATLAB7\work\saranya\cameraman.tif');
            s=edge(a,'LoG')
            imshow(s);
        case 5
            disp('5 -> Zero crossing');
            a=imread(
'D:\h3.jpg');
            s=edge(a,'Zerocross')
            imshow(s);
        case 6
            disp('6 -> Canny');
            a=imread(
'D:\h3.jpg');
            s=edge(a,'canny')
            imshow(s);
       
        otherwise
            disp('Wrong input')
    end
end



-----------------------------------------------------
function c=linedetection()
%Line detection
%===============
%a is a input image
%b is used to user supply a input
a=imread('D:\h3.jpg');a=a(:,:,1);
disp('Line detection');b=input('Enter the value : ');
   
    switch b
        case 1
            disp('Filter a image');
            a=imread('D:\kio.jpg');a=a(:,:,1);
            w=[2 -1 -1;-1 2 -1;-1 -1 2];
            g=imfilter(double(a),w);
            imshow(g,[])
        case 2
            disp('Line detect to the top position');
           
            w=[2 -1 -1;-1 2 -1;-1 -1 2];
            g=imfilter(double(a),w);
            gtop=g(1:120,1:120);
            %gtop=pixeldup(gtop,4);
            figure,imshow(gtop,[])
        case 3
            disp('Line detect to the bottom position');
            w=[2 -1 -1;-1 2 -1;-1 -1 2];
            g=imfilter(double(a),w);
            gtop=g(1:120,1:120);
            %gtop=pixeldup(gtop,4);
            gbot=g(end-119:end,end-119:end);
            %gbot=pixeldup(gbot,4);
            figure,imshow(gbot,[])
        case 4
            disp('Line detect using absolute value');
            w=[2 -1 -1;-1 2 -1;-1 -1 2];
            g=imfilter(double(a),w);
            gtop=g(1:120,1:120);
            %gtop=pixeldup(gtop,4);
            gbot=g(end-119:end,end-119:end);
            %gbot=pixeldup(gbot,4);
            g=abs(g);
            figure,imshow(g,[])
        case 5
            disp('The point to enlarged');
            w=[2 -1 -1;-1 2 -1;-1 -1 2];
            g=imfilter(double(a),w);
            g=abs(g);
            T=max(g(:));
             g=g>=T;
            figure,imshow(g)
        otherwise
            disp('Wrong input');
    end
end
______________________________________________


function c=point(a,b)
%Point detection
%===============
%a is a input image
%b is used to user supply a input
disp('Point detection');
while b<=3
    b=input('Enter the value : ');
    switch b
        case 1
            a=imread('D:\fff.tif');
             w=[0 0 0;1 1 1;0 1 0];
             g=abs(imfilter(double(a),w));
             T=max(g(:));
             g=g>=T;
            imshow(a),figure,imshow(g)
        case 2
            a=imread('D:\mm.tif');
             w=[1 1 1;1 1 1;0 0 0];
             g=abs(imfilter(double(a),w));
             T=max(g(:));
             g=g>=T;
            imshow(a),figure,imshow(g)
            case 3
            a=imread('D:\RUG2.tif');
             w=[0 0 0;1 0 1;0 0 0];
             g=abs(imfilter(double(a),w));
             T=max(g(:));
             g=g>=T;
            imshow(a),figure,imshow(g)
        otherwise
            disp('Wrong input');
    end
end
-------------------------------------------------

function f=mat(f)
f=imread('D:\moon.tif');
c=mat2huff(f);
cr1=imratio(f,c);
end
------------------------------- 

No comments:

Post a Comment