title: how to plot the histogram of the segmented line of document images
body: <p>I am writing a program for line segmentation and I want to plot a horizontal histogram of the input image and the segmented lines, but I don't know the code for plotting histograms. Please help me, I have given my program below:</p>
  
  <pre><code>  close all;
  clear all;
  clc;
  
  im=imread('test_img.tif');%read the image
  figure, imshow(im);
  title('INPUT IMAGE WITH NOISE');
  area(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,15); %% Remove all object containing fewer than 60 pixels
  figure(2) %% Show image binary image
  imshow(~im);
  title('INPUT IMAGE WITHOUT NOISE')
  
  
  %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 &gt;= 20 in length.
  fiveLongRegions = find([measurements.Area] &gt;= 5);
  theIndexes = vertcat(measurements(fiveLongRegions).PixelIdxList);
  c=a;
  c(theIndexes,:)=0;
  figure, imshow(c);
  title('AREA OF INTEREST FOR LINE SEGMENT');
  
  
  
  %Segmentation of line:
  [x,y]=size(a);
  mat1=sum(a,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&lt;((q/2)+1);%number of loops=number of lines
      k=1;
      mat5=([]);
         for j=(index1(lam)+1):1:index1(lam+1)
           mat5(k,:)=a(j,:); %store the line segmented matrix
             k=k+1;
         end
  
  
              lam=lam+2;   
          kap=kap+1;
  
         figure, imshow(mat5);
         imsave();
  end
  </code></pre>