how to get an vertical histogram of an binary image and based on that histogram segment words from a row

后端 未结 2 1541
鱼传尺愫
鱼传尺愫 2021-01-17 05:25

suppose i have an image in which there are some letters.based on those letters of the image i want to show the vertical projections of histogram of the given image in an a

2条回答
  •  借酒劲吻你
    2021-01-17 05:51

    This is the code i was looking for my question

     clear all;
    cd('C:\Users\IFIM\Desktop\New folder\KANND_HAND_SET');
    myFolder = 'C:\Users\IFIM\Desktop\segment';
    [filename, pathname] = uigetfile('*.bmp','Select image to be read.');
    i= imread(fullfile(pathname,filename));
    i=padarray(i,[0 10]);
    verticalProjection = sum(i, 1);
    set(gcf, 'Name', 'DEMO BY SOUMYADEEP', '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)); 
    [L,num] = bwlabel(subImage);
    for z= 1 : num
    bw= ismember( L, z);
    % Construct filename for this particular image.
    baseFileName = sprintf('curvedimage %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);
    subplot(2,2,4);
    pause(2);
    imshow(bw);
    end;
    y=y+1;
    end;
    

提交回复
热议问题