What is the default pixel type of imread create? I test different images, all of them give me unsigned
char with different channels. Would imread create a pixel type with signed char if I do not ask it
explicitly?
cv::Mat img = cv::imread("lena.jpg", -1); //always give me unsigned char
I checked the document of cv::imread, but it said nothing about the default pixel of imread create.
The link of the document
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat imread(const string& filename, int flags)
Most
.jpgimages are 8 bit images. Therfore their default data-type isunsigned charorchar.Some images like
.pngor.tifalso support 16 bit pixel value, so their data type isunsigned short. But it is not necessary as they may be 8 bit.To load the image as-is in OpenCV, use imread like this:
There are different combinations of these flags:
Load as 8 bit (whatever the original depth is):
CV_LOAD_IMAGE_COLORLoad with original depth:
CV_LOAD_IMAGE_COLOR | CV_LOAD_IMAGE_ANYDEPTHLoad as grayscale (no matter how many channels the image has):
CV_LOAD_IMAGE_GRAYSCALELoad as grayscale with original depth:
CV_LOAD_IMAGE_GRAYSCALE| CV_LOAD_IMAGE_ANYDEPTHIn your case,
lena.jpgis 8 bit image, so you are gettingunsigned chardata type.Update:
For newer versions of OpenCV, use the flags defined by enum in the C++ interface. Just replace
CV_LOAD_IMAGE_*withcv::IMREAD_*.e.g.
CV_LOAD_IMAGE_GRAYSCALEbecomescv::IMREAD_GRAYSCALE.