Background information: I need to load some 16 bit grayscale PNGs.
Does Caffe support loading 16 bit images through the ImageDataLayer
?
After some googling, the answer seems it doesn't.
The ImageDataLayer
relies on this io routine
cv::Mat ReadImageToCVMat(const string& filename,
const int height, const int width, const bool is_color) {
cv::Mat cv_img;
int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
if (!cv_img_origin.data) {
LOG(ERROR) << "Could not open or find file " << filename;
return cv_img_origin;
}
if (height > 0 && width > 0) {
cv::resize(cv_img_origin, cv_img, cv::Size(width, height));
} else {
cv_img = cv_img_origin;
}
return cv_img;
}
Which uses opencv's cv::imread
function. This function will read the input as 8bits unless the appropiate flag is set
CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
Simply adding the appropriate flag will not work because later in the code [io.cpp] they check for 8bit depth:
void CVMatToDatum(const cv::Mat& cv_img, Datum* datum) {
CHECK(cv_img.depth() == CV_8U) << "Image data type must be unsigned byte";
... }
I could just remove the check but I'm afraid it's there for a reason and unpredictable results might happen. Can anybody shine light on this issue?