lundi 13 juin 2016

How to save the segmented image automatically

I did a program on matlab for character segmentation of bengali script and i want to save the series of segmented image automatically in a specific folder. So anyone help me with the matlab code for saving image automatic

%%LINES SEGMENTATION:

close all;
clear all;
clc;

im=imread('page_1.tif');%read the image
%figure, imshow(im);
%%title('INPUT IMAGE WITH NOISE');
qw=im;

if size(im,3)==3 % RGB image %% Convert to gray scale
    im=rgb2gray(im);
end
threshold = graythresh(im); %% Convert to binary image
im =~im2bw(im,threshold);
im = bwareaopen(im,10); %% Remove all object containing fewer than 60 pixels
%figure(2) %% Show image binary image
%imshow(~im);
%title('INPUT IMAGE WITHOUT NOISE');
%figure, area(im);

%find Area of Interest:
a=(~im);
ijk=~a;
xy=sum(ijk,2);
measurements = regionprops(xy == 0, 'Area', 'PixelIdxList');
%Get indexes of those regions that are >= 20 in length.
fiveLongRegions = find([measurements.Area] >= 3);
theIndexes = vertcat(measurements(fiveLongRegions).PixelIdxList);
c=a;
c(theIndexes,:)=0;
%figure, imshow(c);
%title('AREA OF INTEREST FOR LINE SEGMENT');
ca=~c;
%Segmentation of line:
[x,y]=size(ca);
mat1=sum(ca,2);%sum the elements of bwrowise and save into column matrix mat1
mat2=y-mat1;%subtract each element of the sum matrix(mat1) from the width length(no. of columns)
mat3=mat2~=0;
mat4=diff(mat3);
index1=find(mat4);
[q,w]=size(index1);%size of index2 matrix is q*w
kap=1;
lam=1;
%iii=1;
%ii=1;
while kap<((q/2)+1);%number of loops=number of lines
    k=1;
    mat5=([]);
       for j=(index1(lam)+1):1:index1(lam+1)
         mat5(k,:)=c(j,:); %store the line segmented matrix
           k=k+1;
       end


            lam=lam+2;   
        kap=kap+1;

       figure, imshow(mat5);
       %%imsave();



       %%WORDS SEGMENTATION:

        bwword=im2bw(mat5);%convert the image im into binary(black and white)
        aword=~bwword;


        bword=sum(aword,1);
        %%figure, area(b);

        %%Measure lengths of all "0" regions.
        measurementsword = regionprops(bword == 0, 'Area', 'PixelIdxList');

        % Get indexes of those regions that are >= 20 in length.
        fiveLongRegionsword = find([measurementsword.Area] >= 5);
        theIndexesword = vertcat(measurementsword(fiveLongRegionsword).PixelIdxList);
        cword=aword;
        cword(:,theIndexesword)=1;
        %%figure, imshow(c);

        dword=~cword;
        %%figure, imshow(dword);
        %%title('AREA OF INTERESRT FOR WORD SEGMENTATION IMAGE');


        [xword,yword]=size(cword);
        mat1word=sum(cword,1);%sum the elements of bwrowise and save into column matrix mat1
        mat2word=xword-mat1word;%subtract each element of the sum matrix(mat1) from the width length(no. of columns)
        mat3word=mat2word~=0;
        mat4word=diff(mat3word);
        index1word=find(mat4word);
        [qword,wword]=size(index1word);%size of index2 matrix is q*w
        kapword=1;
        lamword=1;
        %%iii=1;
        %%ii=1;

         while kapword<((wword/2)+1);%number of loops=number of lines
    kword=1;
    mat5word=([]);
       for jword=(index1word(lamword)+1):1:index1word(lamword+1)
         mat5word(:,kword)=bwword(:,jword); %store the word segmented matrix
           kword=kword+1;
       end


            lamword=lamword+1;   
       kapword=kapword+1;

       figure, imshow(mat5word);
       %imsave();


         %%CHARACTER SEGMENTATION:


       bwcha=im2bw(mat5word);%convert the image im into binary(black and white)
        acha=~bwcha;

        mat1cha=sum(a,2);
        %figure, area(mat1);
        xcha=find(mat1cha>70);
        ycha=acha;
        ycha(xcha,:)=0;
        ycha = bwareaopen(ycha,20);
        figure,imshow(ycha);
        %figure, area(y);
        %mat2=sum(y,2);
        %x1=find(mat2<7);
        %y1=y;
        %y1(x1,:)=0;
        %y1 = bwareaopen(y1,15);
        %z=~y1;
        %figure, imshow(z);

        [Lcha, bcha,]=bwlabel(ycha);   %% Label connected components
        propiedcha=regionprops(Lcha,'BoundingBox');  %% Measure properties of image regions
        for ncha=1:size(propiedcha,1)  %% Plot Bounding Box
        rectangle('Position',propiedcha(ncha).BoundingBox,'EdgeColor','g','LineWidth',1);
        end


        for ncha=1:bcha   %% Objects extraction
            [rcha,ccha] = find(Lcha==ncha);
         n1cha=ycha(min(rcha):max(rcha),min(ccha):max(ccha));
            figure, imshow(~n1cha);
            %pause(0.2)
            %imsave();
        end







        end

end





`enter co%%LINES SEGMENTATION:

close all;
clear all;
clc;

im=imread('page_1.tif');%read the image
%figure, imshow(im);
%%title('INPUT IMAGE WITH NOISE');
qw=im;

if size(im,3)==3 % RGB image %% Convert to gray scale
    im=rgb2gray(im);`enter code here`
end
threshold = graythresh(im); %% Convert to binary image
im =~im2bw(im,threshold);
im = bwareaopen(im,10); %% Remove all object containing fewer than 60 pixels
%figure(2) %% Show image binary image
%imshow(~im);
%title('INPUT IMAGE WITHOUT NOISE');
%figure, area(im);

%find Area of Interest:
a=(~im);
ijk=~a;
xy=sum(ijk,2);
measurements = regionprops(xy == 0, 'Area', 'PixelIdxList');
%Get indexes of those regions that are >= 20 in length.
fiveLongRegions = find([measurements.Area] >= 3);
theIndexes = vertcat(measurements(fiveLongRegions).PixelIdxList);
c=a;
c(theIndexes,:)=0;
%figure, imshow(c);
%title('AREA OF INTEREST FOR LINE SEGMENT');
ca=~c;
%Segmentation of line:
[x,y]=size(ca);
mat1=sum(ca,2);%sum the elements of bwrowise and save into column matrix mat1
mat2=y-mat1;%subtract each element of the sum matrix(mat1) from the width length(no. of columns)
mat3=mat2~=0;
mat4=diff(mat3);
index1=find(mat4);
[q,w]=size(index1);%size of index2 matrix is q*w
kap=1;
lam=1;
%iii=1;
%ii=1;
while kap<((q/2)+1);%number of loops=number of lines
    k=1;
    mat5=([]);
       for j=(index1(lam)+1):1:index1(lam+1)
         mat5(k,:)=c(j,:); %store the line segmented matrix
           k=k+1;
       end


            lam=lam+2;   
        kap=kap+1;

       figure, imshow(mat5);
       %%imsave();



       %%WORDS SEGMENTATION:

        bwword=im2bw(mat5);%convert the image im into binary(black and white)
        aword=~bwword;


        bword=sum(aword,1);
        %%figure, area(b);

        %%Measure lengths of all "0" regions.
        measurementsword = regionprops(bword == 0, 'Area', 'PixelIdxList');

        % Get indexes of those regions that are >= 20 in length.
        fiveLongRegionsword = find([measurementsword.Area] >= 5);
        theIndexesword = vertcat(measurementsword(fiveLongRegionsword).PixelIdxList);
        cword=aword;
        cword(:,theIndexesword)=1;
        %%figure, imshow(c);

        dword=~cword;
        %%figure, imshow(dword);
        %%title('AREA OF INTERESRT FOR WORD SEGMENTATION IMAGE');


        [xword,yword]=size(cword);
        mat1word=sum(cword,1);%sum the elements of bwrowise and save into column matrix mat1
        mat2word=xword-mat1word;%subtract each element of the sum matrix(mat1) from the width length(no. of columns)
        mat3word=mat2word~=0;
        mat4word=diff(mat3word);
        index1word=find(mat4word);
        [qword,wword]=size(index1word);%size of index2 matrix is q*w
        kapword=1;
        lamword=1;
        %%iii=1;
        %%ii=1;

         while kapword<((wword/2)+1);%number of loops=number of lines
    kword=1;
    mat5word=([]);
       for jword=(index1word(lamword)+1):1:index1word(lamword+1)
         mat5word(:,kword)=bwword(:,jword); %store the word segmented matrix
           kword=kword+1;
       end


            lamword=lamword+1;   
       kapword=kapword+1;

       figure, imshow(mat5word);
       %imsave();


         %%CHARACTER SEGMENTATION:


       bwcha=im2bw(mat5word);%convert the image im into binary(black and white)
        acha=~bwcha;

        mat1cha=sum(a,2);
        %figure, area(mat1);
        xcha=find(mat1cha>70);
        ycha=acha;
        ycha(xcha,:)=0;
        ycha = bwareaopen(ycha,20);
        figure,imshow(ycha);
        %figure, area(y);
        %mat2=sum(y,2);
        %x1=find(mat2<7);
        %y1=y;
        %y1(x1,:)=0;
        %y1 = bwareaopen(y1,15);
        %z=~y1;
        %figure, imshow(z);

        [Lcha, bcha,]=bwlabel(ycha);   %% Label connected components
        propiedcha=regionprops(Lcha,'BoundingBox');  %% Measure properties of image regions
        for ncha=1:size(propiedcha,1)  %% Plot Bounding Box
        rectangle('Position',propiedcha(ncha).BoundingBox,'EdgeColor','g','LineWidth',1);
        end


        for ncha=1:bcha   %% Objects extraction
            [rcha,ccha] = find(Lcha==ncha);
         n1cha=ycha(min(rcha):max(rcha),min(ccha):max(ccha));
            figure, imshow(~n1cha);
            %pause(0.2)
            %imsave();
        end







        end

end





de here`ally i am providing my code

Aucun commentaire:

Enregistrer un commentaire