int PartialRecomposeImageWithBoundaries( const vector<float> &im_subdivide, const ImageSize &imSize_subdivide, const ImageSize &imSize_output, const int &h_offset, const int &w_offset, const int &boundary_length, const int &boundary_w_length, const int &boundary_h_length, vector<float> *im_output ) { //! Compute the image for(int c=0; c<imSize_output.nChannels; ++c) { for(int w=0; w<imSize_subdivide.width-boundary_w_length; ++w) //X { if(w+w_offset >= imSize_output.width) continue; for(int h=0; h<imSize_subdivide.height-boundary_h_length; ++h) //X { if(h+h_offset >= imSize_output.height) continue; im_output->at(imSize_output.at(h+h_offset, w+w_offset, c)) = im_subdivide[imSize_subdivide.at(h+boundary_length, w+boundary_length, c)]; } } } return EXIT_SUCCESS; }
int ExtractSubImageWithBoundary( const vector<float> &im_input, const ImageSize &imSize_input, const ImageSize &imSize_output, const size_t &h_offset, const size_t &w_offset, const size_t &boundary_length, vector<float> *im_output ) { im_output->resize(imSize_output.whc); for(int c=0; c<imSize_output.nChannels; ++c) { for(int w=0; w<imSize_output.width; ++w) { for(int h=0; h<imSize_output.height; ++h) { im_output->at(imSize_output.at(h,w,c)) = im_input[imSize_input.symmetrise_at(h-boundary_length+h_offset, w-boundary_length+w_offset, c)]; } } } return EXIT_SUCCESS; }
vector<float> ExtractCenteredPatches( const vector<float> &im_input, const ImageSize &imSize, const int l ) { const int length = 2*l+1; const int dim_patch = length*length; const int im_height = imSize.height-2*l; const int im_width = imSize.width-2*l; const int im_wh = im_height*im_width; const int number_patch = im_height*im_width*imSize.nChannels; vector<float> patches(number_patch*dim_patch); int c=0; for(int w=l; w<imSize.width-l; ++w) { for(int h=l; h<imSize.height-l; ++h) { for(int j=-l; j<=l; ++j) { for(int i=-l; i<=l; ++i) { size_t pos_patch = i+l + (j+l)*length; size_t pos_pixel = (h-l) + (w-l)*im_height + c*im_wh; patches[pos_pixel*dim_patch + pos_patch] = im_input[imSize.at(h+i, w+j, c)]; } } } } return patches; }
vector<float> ExtractPatches( const vector<float> &im_input, const ImageSize &imSize, const int length ) { const int dim_patch = length*length*imSize.nChannels; const int im_height = imSize.height-length; const int im_width = imSize.width-length; const int number_patch = im_height*im_width; vector<float> patches(number_patch*dim_patch); for(int c=0; c<imSize.nChannels; ++c) { for(int w=0; w<im_width; ++w) { for(int h=0; h<im_height; ++h) { for(int j=0; j<length; ++j) { for(int i=0; i<length; ++i) { size_t pos_patch = i + j*length + c*length*length; size_t pos_pixel = h + w*im_height; patches[pos_pixel*dim_patch + pos_patch] = im_input[imSize.at(h+i, w+j, c)]; } } } } } return patches; }
int saveImage( const char *p_name, const vector<float> &i_im, const ImageSize &p_imSize, const float &p_min, const float &p_max ) { float* imTmp = new float[p_imSize.whc]; for(int _c=0; _c<p_imSize.nChannels; ++_c) { for(int _h=0; _h<p_imSize.height; ++_h) { for(int _w=0; _w<p_imSize.width; ++_w) { imTmp[_c*p_imSize.wh + _h*p_imSize.width + _w] = i_im[p_imSize.at(_h,_w,_c) ]; } } } //! Check for boundary problems for (int k = 0; k < p_imSize.whc; k++) { imTmp[k] = imTmp[k] < p_min ? p_min : (imTmp[k] > p_max ? p_max : imTmp[k]); } if (write_png_f32(p_name, imTmp, p_imSize.width, p_imSize.height, p_imSize.nChannels) != 0) { cout << "... failed to save png image :'" << p_name << "'" << endl; return EXIT_FAILURE; } delete[] imTmp; return EXIT_SUCCESS; }
int loadImage( const char* p_name, vector<float> &o_im, ImageSize &o_imSize, const bool p_verbose ) { if (p_verbose) { cout << endl << "Read input image '" << p_name << "'..."; } size_t w, h, c; float *imTmp = read_png_f32(p_name, &w, &h, &c); if (!imTmp) { cout << "error :: " << p_name << " not found or not a correct png image" << endl; return EXIT_FAILURE; } if (p_verbose) { cout << "done." << endl; } //! test if image is really a color image and exclude the alpha channel if (c == 2) { cout << "The gray image has a alpha channel. We will remove it." << endl; c = 1; } else if(c >= 3) { cout << "Parigi does not work with color images." << endl; exit(-1); } if (p_verbose) { cout << "image size :" << endl; cout << " - width = " << w << endl; cout << " - height = " << h << endl; cout << " - nb of channels = " << c << endl; } o_imSize.width = w; o_imSize.height = h; o_imSize.nChannels = c; o_imSize.wh = w * h; o_imSize.whc = w * h * c; o_im.resize(w * h * c); for(size_t _c=0; _c<c; ++_c) { for(size_t _h=0; _h<h; ++_h) { for(size_t _w=0; _w<w; ++_w) { o_im[o_imSize.at(_h,_w,_c)] = imTmp[_c*w*h + _h*w + _w]; } } } delete[] imTmp; return EXIT_SUCCESS; }