Decomposing an image to several subimages
Hello, I am gonna divide a 48004800 RGB image (Host_Image) to 1616 RGB sub-images each consisting of 300*300 pixels. Sub_Image (0,0): Host_Image(0, 0), Host_Image(0, 16), Host_Image(0, 32), … Host_Image(16, 0), Host_Image(16,16), Host_Image(16, 32), … …
Host_Image(4784, 0), Host_Image(4784,16), Host_Image(4784, 32), …
Sub_Image (0,1): Host_Image(0, 1), Host_Image(0, 17), Host_Image(0, 33), … Host_Image(16, 1), Host_Image(16,17), Host_Image(16, 33), … …
Host_Image(4785, 0), Host_Image(4785,16), Host_Image(4785, 32), …
Sub_Image (1, 0): Host_Image(1, 0), Host_Image(17, 0), Host_Image(33, 0), … Host_Image(17, 0), Host_Image(17,16), Host_Image(17, 32), … … Host_Image(4785, 0), Host_Image(4785,16), Host_Image(4785, 32), …
It may seem a super-banal task. But when I save the sub-images, the saved values are totally different with the pixels of the host image. I obtain 16*16 error log which shows some pixels are mapped correctly while many others are nor. Any idea?
vector<Mat> res;
register unsigned int i1, j1, k, l;
//pixels_num= the number of pixels per uI
char str[200], cnt;
uchar n_ch = po.channels();
Sub_Image_Width = 300;
Sub_Image_Length = 300;
Mat temp(Sub_Image_Width, Sub_Image_Length, CV_8UC3);
FILE *pfile;
unsigned long int ttt = 0, x_host, y_host, pl_idx;
int x_pos, y_pos;
x_pos = wherex();
y_pos = wherey();
for (i1 = 0;i1 < n_Hor_Sub_Img;i1++)
for (j1 = 0;j1 < n_Ver_Sub_Img;j1++)
{
x_host = i1;
y_host = j1;
sprintf(str, "Cont%lu-%lu.txt", i1, j1);
pfile = fopen(str, "w");
for (k = 0;k < Sub_Image_Width;k++)
{
for (l = 0; l < Sub_Image_Length; l++)
{
//puchar_ii[ii_idx + cnt] = puchar_po[po_idx + cnt];
for (cnt = 0; cnt < n_ch; cnt++)
{
temp.at<Vec3b>(k, l)[cnt] = Main_Image.at<Vec3b>(x_host, y_host)[cnt];
sprintf(str, "temp(%lu, %lu, %lu)= %d, IN_PO(%lu, %lu, %lu)= %d\n", k, l,
cnt, temp.at<Vec3b>(k, l)[cnt], x_host, y_host, cnt,
Main_Image.at<Vec3b>(x_host, y_host)[cnt]);
fputs(str, pfile);
}
y_host = y_host + n_Ver_Sub_Img;
ttt++;
}
gotoxy(x_pos, y_pos);
printf("%5.3f%% Completed", double(100 * ttt) / double(n_Hor_Sub_Img*n_Ver_Sub_Img*Sub_Image_Width*Sub_Image_Length));
y_host = j1;
x_host = x_host + n_Hor_Sub_Img;
}
res.push_back(temp);
fclose(pfile);
}
//cout << "size of ii= " << int(Main_Image.size()) << endl;
puts("\n******************************************************************");
x_pos = wherex();
y_pos = wherey();
ttt = 0;
for (i1 = 0;i1 < n_Hor_Sub_Img;i1++)
for (j1 = 0;j1 < n_Ver_Sub_Img;j1++)
{
x_host = i1;
y_host = j1;
sprintf(str, "/error_Image_%lu-%lu.txt", i1, j1);
pfile = fopen(str, "w");
temp = res[j1 + (i1*n_Hor_Sub_Img)];
for (k = 0;k < Sub_Image_Width;k++)
{
for (l = 0; l < Sub_Image_Length; l++)
{
//puchar_ii[ii_idx + cnt] = puchar_po[po_idx + cnt];
for (cnt = 0; cnt < n_ch; cnt++)
{
if (temp.at<Vec3b>(k, l)[cnt] != Main_Image.at<Vec3b>(x_host, y_host)[cnt])
{
sprintf(str, "temp(%lu, %lu, %lu)= %d, IN_PO(%lu, %lu, %lu)= %d\n", k, l,
cnt, temp.at<Vec3b>(k, l)[cnt], x_host, y_host, cnt,
Main_Image.at<Vec3b>(x_host, y_host)[cnt]);
fputs(str, pfile);
}
}
y_host = y_host + n_Ver_Sub_Img;
ttt++;
}
gotoxy(x_pos, y_pos);
printf("%5.3f%% Completed", double(100 * ttt) / double(n_Hor_Sub_Img*n_Ver_Sub_Img*Sub_Image_Width*Sub_Image_Length));
y_host = j1;
x_host = x_host + n_Hor_Sub_Img;
}
fclose(pfile);
}
return res;
}
I have never seen an
O(n^5)
implementation before.