如何保存分割结果的精确图像(使用垂直投影法分割)?

How to save exact image of segmentation result (segmentation using vertical projection method)?

我已经修改了分割过程的代码。代码如下:

% Preprocessing + Segmentation (VP with secondary element)
% // Original Code of Vertical Projection for Segmentation by Soumyadeep Sinha //
% // Modified by Ana Ainul S. : anaainul@gmail.com, Last modified : 14/07/16 //
% Saving each  single segmented character as one file 

function [ss] = segment (a)
myFolder = 'D:. Thesis FINISH!!!\Data set';

%% Binarization %%
level = graythresh (a);
b = im2bw (a, level);
%% Complement %
c = imcomplement (b);
i=padarray(c,[0 10]);

% Vertical Projecttion for Character Segmentation
verticalProjection = sum(i, 1);
set(gcf, 'Name', 'Segmentation Trial', 'NumberTitle', 'Off') 
subplot(2, 2, 1);imshow(i); 
subplot(2,2,3);
plot(verticalProjection, 'b-');
grid on;
t = verticalProjection;
t(t==0) = inf;
mayukh=min(t)
% 0 where there is background, 1 where there are letters
letterLocations = verticalProjection > mayukh; 
% Find Rising and falling edges
d = diff(letterLocations);
startingColumns = find(d>0);
endingColumns = find(d<0);

% Extract each region
y=1;
for k = 1 : length(startingColumns)
  % Get sub image of just one character...
  subImage = i(:, startingColumns(k):endingColumns(k)); 
  s = subImage;
  figure, imshow (s);

  % Save each segmented characters %
  [L,num] = bwlabel(s);
  for z = 1 : num
     bw= ismember(L, z);
     % Construct filename for this particular image.
     baseFileName = sprintf('data1.%d.png', y);
     y=y+1;
     % Prepend the folder to make the full file name.
     fullFileName = fullfile(myFolder, baseFileName);
     % Do the write to disk.
     imwrite(bw, fullFileName);
   end
end;
ss = (s);

它给出了一个很好的结果,但是当我需要将它保存为每个分割图像的一个文件时我遇到了一些麻烦。

正在分割字符。

当我保存它时,它给了我一个不同的结果。

当我试图保存时,应该与角色主体结合的次要元素被分离了。我试图修改代码,但仍然没有得到解决方案。 我需要保存与程序中显示的完全相同的图像。

任何帮助,将不胜感激。

非常感谢。

您有两种不同的方法来分割代码中的字符:
一个是循环 for k = 1 : length(startingColumns),您可以在其中正确按列分段,
并且在前一个之上通过连接组件(bwlabel)进行第二个不同分割。

如果我对你的需求理解正确,你不需要对每个字符进行第二次bwlabel处理。

for k = 1 : length(startingColumns)
    % Get sub image of just one character...
    subImage = i(:, startingColumns(k):endingColumns(k)); 
    s = subImage;
    figure, imshow (s);
    imwrite( s, fullfile( baseFolder, sprintf('data.%d.png', k ) ) );
end

PS,
祝你论文顺利 ;)