2014-07-08 2 views
-1

나는 bengali 스크립트의 문자 세분화를 위해 matlab에서 프로그램을 작성했으며 일련의 분할 된 이미지를 특정 폴더에 자동 저장하려고합니다. 그래서 사람이 당신이 당신의 코드의 끝 부분에 모두 표시 n1cha 이미지를 폴더로 작성하려고하는 가정분할 된 이미지를 자동으로 저장하는 방법

%%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 
+0

여기에 모든 코드를 덤프 할 수는 없으며 (문제가있는 형식이 아닙니다.) 문제가있는 부분을 이해할 수있을 것입니다. 당신은 ** 매우 ** 구체적이어야합니다 ** ** : 당신은 무엇을하고 있으며, 정확히 어디에 문제가 있습니까 – Shai

답변

0

자동으로 이미지를 저장하기위한 MATLAB 코드를 도와.

당신은 당신이 이미 저장 한 후 문자 저장 imwrite를 사용하여 얼마나 많은 문자를 카운트하는 카운터 유지해야합니다 : 당신의 이름 '폴더'와 함께 폴더에 저장하려면

% init variables before loop 
imgFolder = 'path/to/saved/images'; 
counter = 1; 
while kap<((q/2)+1);%number of loops=number of lines 
     % your code here... nested loops... 
     % ... 
     % finally you get to this loop: 
     for ncha=1:bcha 
      % extract the character... 
      imwrite(n1cha, fullfile(imgFolder, sprintf('char_%04d.png', counter))); 
      counter = counter + 1; 
     end 
end 
0

을, 여기에 (코드를 사용하고 복사하여 붙여 넣습니다.)

folder = "Folder"; // **the path and name of your folder**<br/> 
for ncha=1:bcha %% Objects extraction<br/> &nbsp;&nbsp;&nbsp;&nbsp; 
    [rcha,ccha] = find(Lcha==ncha);<br/> &nbsp;&nbsp;&nbsp;&nbsp; 
    n1cha=ycha(min(rcha):max(rcha),min(ccha):max(ccha));<br/> &nbsp;&nbsp;&nbsp;&nbsp; 
    figure, imshow(~n1cha);<br/> &nbsp;&nbsp;&nbsp;&nbsp; 
    imwrite(n1cha, folder); **//code to save it to folder 'Folder' automatically**<br/> 
end 
관련 문제