Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

i want to segment the horizontal row of characters from a image for which i am using code given below to the images i cant get why working process is "stucking after the histogram process" and after some time it start again with taking image as input and showing it's histogram and taking too much time then repeating the same. some one please help me to code it correctly i can't find where there is error and i am also confused at

darkPixels = h< 1500; % Threshold label

line of code i am not very sure what value i need to take whether it be h< 1500 or something else Please help with regards

input image that i have taken histogram of taken image

% Find the dark lanes that define the zones between the lines with letters on them.
    % Rather than find the letters themselves, we will find the dark spaces between the lines.
    % Then we will go from the center of each one of those to the center of the next one down the page.
    darkPixels = h< 1500; % Threshold label
    [labeledRegions, numberOfRegions] = bwlabel(darkPixels);
    fprintf('Number of regions = %d\n', numberOfRegions);
    % Find centroids
    measurements = regionprops(labeledRegions, 'Centroid');
    % Get them into an array
    allCentroids = [measurements.Centroid];
    xCentroids = int32(allCentroids(1:2:end));
    yCentroids = int32(allCentroids(2:2:end));
    fprintf('I found %d black spaces between the lines of text\n', length(yCentroids));
    % Now you can just crop out some line of text you're interested in, into a separate image:
    plotLocation = 12;
    for band = 1 : numberOfRegions-1
        row1 = xCentroids(band);
        row2 = yCentroids(band+1);
        thisLine = a(row1 : row2, :);
        pause(3)
        subplot(10, 2, plotLocation);
        pause(3)
        imshow(thisLine, []);
        pause(3)
        plotLocation = plotLocation + 2;
    end
share|improve this question

You need first to clean a little bit your image in order to simplify things. Try the following approach:

  1. Small opening (delete the small isolated components).
  2. Small closing (reconnect the close components)
  3. (optional) Connected components labeling in order to separate each letter (you will certainly need it later)
  4. Then, you can use the histogram projection which is going to be much easier to analyze. You should see as many peaks as rows in your signal.
  5. (optional) If the histogram is not clean enough, use a median filter coupled with a gaussian filter in order to denoise and smooth your signal.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.