Image data accessing issue(read/write)
I have a Mat Image single channel variable,when i store the same image variable into the disk using imwrite and then access it using imread as a single channel image itself, the data are totally diffrent(i.e, before stroing into disk and after reading it from disk).
What couble be the issue and how can i fix it.i am posting a small snippet below. Please note image variable is always single Channel.
After executing both the files contain diffrent result(i.e, image data).
The main problem is if i use the image variable i get wierd results but when i save the iamge to disk and again read it i get result as desired.
foo(Mat &image)
{
FILE *fp = fopen("Before.txt","w+");
fprintf(fp,"TYPE = %d\n",image.type());
fprintf(fp,"CHANNELS = %d\n",image.channels());
fprintf(fp,"DEPTH = %d\n",image.depth());
fprintf(fp,"STEP = %d\n",image.step);
for(int i = 0 ; i < image.rows;i++)
{
for(int j = 0; j < image.cols;j++)
{
fprintf(fp,"%d\t",image.data[i*image.cols+j]);
}
fprintf(fp,"\n");
}
fclose(fp);
imwrite("image.bmp",image);
image = cv::imread("image.bmp",CV_LOAD_IMAGE_GRAYSCALE);
FILE *fp1 = fopen("After1.txt","w+");
fprintf(fp1,"TYPE = %d\n",arrSegmentImg.type());
fprintf(fp1,"CHANNELS = %d\n",arrSegmentImg.channels());
fprintf(fp1,"DEPTH = %d\n",arrSegmentImg.depth());
fprintf(fp1,"STEP = %d\n",arrSegmentImg.step);
uchar* p1 = arrSegmentImg.data;
for(int i = 0 ; i < arrSegmentImg.rows;i++)
{
for(int j = 0; j < arrSegmentImg.cols;j++)
{
fprintf(fp1,"%d\t",image.data[i*image.cols+j]);
}
fprintf(fp1,"\n");
}
fclose(fp1);
}