Removing lines of certain length from an image in MATLAB
This is a program which removes the line segments in a single column of length which is more than the threshold

function [ret_im] = remove_vertical(in_image)


[NZ_r, NZ_c] = find(in_image);

ori = in_image;

%scan through each row of location of non-zero pixels 
% If three (threshold) or more pixels are placed in a single column, turn them to zero
thresh = 3;
for i=1:1:size(NZ_r,1)-1

    probe = NZ_c(i); % Set the initial search element
    len = length(find(NZ_c(:)==probe));
    if( len &gt; thresh)
        for j=1:1:len
            if((NZ_r(i+1) - NZ_r(i)) == 1)
                in_image(NZ_r(i),NZ_c(i)) = 0;
            end
        end
    end
end

ret_im = in_image;

end