Skip to content

Commit

Permalink
imread
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallick committed Apr 7, 2015
1 parent 8023292 commit 146d146
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
Binary file added imread/earth-16-bit-per-channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imread/earth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions imread/imread_examples.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* OpenCV SimpleBlobDetector Example
*
* Copyright 2015 by Satya Mallick <spmallick@gmail.com>
*
*/

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

string type2str(int type) {
string r;

uchar depth = type & CV_MAT_DEPTH_MASK;

switch ( depth ) {
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
case CV_16S: r = "16S"; break;
case CV_32S: r = "32S"; break;
case CV_32F: r = "32F"; break;
case CV_64F: r = "64F"; break;
default: r = "User"; break;
}

return r;
}


int main( int argc, char** argv )
{
// Read 8-bit grayscale image
Mat im = imread("earth-16-bit-per-channel.png", IMREAD_GRAYSCALE);
cout << "flags : IMREAD_GRAYSCALE" << endl;
cout << "Number of Channels : " << im.channels() << ", depth : " << type2str(im.depth()) << endl << endl;

// Read 8-bit color image
im = imread("earth-16-bit-per-channel.png", IMREAD_COLOR);
cout << "flags : IMREAD_COLOR" << endl;
cout << "Number of Channels : " << im.channels() << ", depth : " << type2str(im.depth()) << endl << endl;

// Read 16-bit color image
im = imread("earth-16-bit-per-channel.png", IMREAD_ANYCOLOR | IMREAD_ANYDEPTH );
cout << "flags : IMREAD_ANYCOLOR | IMREAD_ANYDEPTH" << endl;
cout << "Number of Channels : " << im.channels() << ", depth : " << type2str(im.depth()) << endl << endl;

// Read transparent PNG / TIFF image
im = imread("earth-16-bit-per-channel.png", IMREAD_UNCHANGED);
cout << "flags : IMREAD_UNCHANGED" << endl;
cout << "Number of Channels : " << im.channels() << ", depth : " << type2str(im.depth()) << endl << endl;
}
22 changes: 22 additions & 0 deletions imread/imread_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python
import cv2

# Read 8-bit grayscale image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_GRAYSCALE)
print "flags : cv2.IMREAD_GRAYSCALE"
print "Size %s, type %s\n" % (im.shape,im.dtype)

# Read 8-bit color image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_COLOR)
print "flags : cv2.IMREAD_COLOR"
print "Size %s, type %s\n" % (im.shape,im.dtype)

# Read 16-bit color image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH )
print "flags : cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH"
print "Size %s, type %s\n" % (im.shape,im.dtype)

# Read transparent PNG / TIFF image
im = cv2.imread("earth-16-bit-per-channel.png", cv2.IMREAD_UNCHANGED)
print "flags : cv2.IMREAD_UNCHANGED"
print "Size %s, type %s\n" % (im.shape,im.dtype)

0 comments on commit 146d146

Please sign in to comment.