Ask Your Question
2

analysis of the vertical and horizontal histogram

asked 2013-07-30 02:58:32 -0600

qbeart gravatar image

Hi,I ran into the term "analysis of the vertical and horizontal histogram" explained as "showing the intensity differences between successive rows, pixel-wise". I didn't get the point here. I wonder if there is an OpenCV implementation for this operation or should I implement it by myself? Any clue will help. Thanks.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-07-30 03:05:00 -0600

The histogram calculation function is exactly what you need. What they mean is that you have to perform the histogram calculation on rows and colums. As input you see the image, which is of the Mat type. This can be either a 2D image, or a 1D row or column.

edit flag offensive delete link more

Comments

how can that show the intensity differences between successive rows by performing histogram calculation on rows or colums?

german_iris gravatar imagegerman_iris ( 2017-02-27 06:48:26 -0600 )edit
0

answered 2016-11-10 09:06:17 -0600

essamzaky gravatar image

I couldn't use the histogram functions descriped in openCV doc , because it try to find color histogram , and the question try to find projection in on X-axis and Y-axis for black and white image. i used the following code the find vertical and herozontal projection.

//2-find x ,y projections (horizontal projection)
    Mat horizontal(ROIimg.cols,1,CV_32S);//horizontal histogram
    horizontal = Scalar::all(0);
    Mat vertical(ROIimg.rows,1,CV_32S);//vertical histogram
    vertical = Scalar::all(0);
    for(int i=0;i<ROIimg.cols;i++)
    {
        horizontal.at<int>(i,0)=countNonZero(ROIimg(Rect(i,0,1,ROIimg.rows)));
    }
    for(int i=0;i<ROIimg.rows;i++)
    {
        vertical.at<int>(i,0) = countNonZero(ROIimg(Rect(0,i,ROIimg.cols,1)));
    }

where ROIimg is balck and white

edit flag offensive delete link more

Comments

reduce is doing the same.

berak gravatar imageberak ( 2016-11-10 09:10:33 -0600 )edit

Thanks @berak , but Reduce able to change the type of out array into int to avoid overflow ? , you now the size of Black and white element is 1 byte

essamzaky gravatar imageessamzaky ( 2016-11-10 09:20:16 -0600 )edit

sorry, but where does the overflow happen ? (i did not understand you there)

what size are you talking about ?

berak gravatar imageberak ( 2016-11-10 09:33:40 -0600 )edit

Hi @berak i'm just was expecting that reduce will work as resize and the output will be the same image type one chanel 8 bit per pixel . anyway i tried the function and it crash when called , i use the following

Mat vertMat ;
Mat horzMat ;
reduce(ROIimg,vertMat,1,CV_REDUCE_SUM);
reduce(ROIimg,horzMat,0,CV_REDUCE_SUM);

also i used the following code and also crash

Mat vertMat (ROIimg.rows,1,CV_32S);
    Mat horzMat (1,ROIimg.cols,CV_32S);
    vertMat = Scalar::all(0);
    horzMat = Scalar::all(0);
    reduce(ROIimg,vertMat,1,CV_REDUCE_SUM);
    reduce(ROIimg,horzMat,0,CV_REDUCE_SUM);

how does this function work

essamzaky gravatar imageessamzaky ( 2016-11-10 10:13:19 -0600 )edit

Is your input image one channel? The output is the same number of channels as the input.

Tetragramm gravatar imageTetragramm ( 2016-11-10 11:52:31 -0600 )edit

Yes the ROIimg BW single chanle 8 bit I convert the imput image to gray scale then to black and white

essamzaky gravatar imageessamzaky ( 2016-11-11 06:07:27 -0600 )edit

oops, can it be, it's simply not working correctly with a ROI (non-continuous memory) ?

berak gravatar imageberak ( 2016-11-11 06:18:15 -0600 )edit

thanks @break , it seems this function working correctly i tested the following code and it's working

Mat imgHist = imread("C:\\Temp\\Testreduce.png",IMREAD_GRAYSCALE);
    threshold(imgHist,imgHist,128,255,CV_THRESH_OTSU);
    Mat vertMat, horzMat;   
    reduce(imgHist,vertMat,1,CV_REDUCE_SUM,CV_32S);
    reduce(imgHist,horzMat,0,CV_REDUCE_SUM,CV_32S);

Also the ROI is working ,i just added the last parameter to CV_32S ,

essamzaky gravatar imageessamzaky ( 2016-11-12 12:29:18 -0600 )edit

Question Tools

Stats

Asked: 2013-07-30 02:58:32 -0600

Seen: 6,510 times

Last updated: Nov 10 '16