Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am trying this code to calculate my binary image pixels value by this code :

C++
int main()
{


Mat img;

img=imread("/home/2b.jpeg", CV_LOAD_IMAGE_UNCHANGED);
namedWindow("win", WINDOW_AUTOSIZE);
imshow("win", img);

for(int i=0; i< img.rows ;i++)
{
    for(int j=0; j< img.cols ; j++)
    {
        cout<<setw(10)<<img.at<int>(i,j);
    }
cout<<endl<<endl<<endl;

}

waitKey(0);



    return 0;
}


But i get 3 types of value: 0, -1 and some big different numbers like (24342234 , 1324244242, etc)

What is the problem? I drew one black line in paint programs and save the image, or download binary image from internet but i get same results!

I thought when i use binary images i must get 0 for white pixels and 255 for black ones.
Posted
Comments
varunvidala 29-May-14 3:18am    
Binary Images will have Pixel value of 1 for White and 0 for Dark Pixels. Using "int" is not valid instead use "uchar" for 8bit images
Are you able to watch Output Image in display? if not check the path of the Image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900