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

后端 未结 2 1542
鱼传尺愫
鱼传尺愫 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 06:09

    First of all, you are not looking for a "vertical histogram", but rather a bar plot of vertical sum.

    Here's a simplified example.

    Consider this input image

    You can read and threshold it

    img = imread('http://i.stack.imgur.com/3YonG.png')
    bw = img(:,:,1)<128;  %// convert to binary, text = 1
    

    Now you can inspect the vertical sum

    sc = sum(bw,1);  %// sum columns
    figure;bar(sc);  
    

    As you can see if there are more than ~2 pixels set in a column - this is probably a letter. We can use this threshold

    rm = sc > 2; 
    cs = cumsum(~rm).*rm;  %// assign unique value to each "letter" columns
    mask = bsxfun(@times, bw, cs );  %// seperate the letters in the mask
    

    Resulting with

提交回复
热议问题