void display(const PX_TYPE* img, int w, int h) {
int height = h > 40 ? 40 : h; int width = w > 40 ? 40 : w; int size = w * h * 3;
for (int i = 0; i < 3; i++) { if (i == 0) std::cout << "Red:" << std::endl; else if (i == 1) std::cout << "Green:" << std::endl; else if (i == 2) std::cout << "Blue:" << std::endl; for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { std::cout << std::setw(4) << img[idx(k, j, w, h, i)]; } std::cout << std::endl; }
std::cout << std::endl;
}
std::cout << std::endl;
}
cimg_library::CImg<PX_TYPE> cimg(w, h, 1, 3, 0); for (int i = 0; i < size; i++) { cimg[i] = img[i]; } cimg_library::CImg<PX_TYPE> imgCropped(cimg); imgCropped.crop(0, 0, width - 1, height - 1, 0); imgCropped.display();
}
float* getImage(char* filename, int &w, int &h) {
std::cout << "Trying to read " << filename << std::endl; cimg_library::CImg<PX_TYPE> cimg(filename); std::cout << "Done reading " << filename << std::endl; w = cimg.width(); h = cimg.height(); int size = w * h * cimg.spectrum(); float* img = new PX_TYPE[size]; for (int i = 0; i < size; i++) { img[i] = cimg[i]; } return img;
}</nowiki>
=== Assignment 3 ===