BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Mat(rix) object (Image Container)

OpenCV_Logo.png  height=




Bookmark and Share





bogotobogo.com site search:






Image is a Matrix

Every image is a matrix: it is stored as a matrix and it is manipulated as a matrix.

matrix_Mat_object.png

For more information about getting the images from sensors or how we process them, please visit:

  1. CCD/CMOS image sensors .
  2. Digital Image Processing (JPEG) .



Mat Object - Image Container

OpenCV is an image processing library which contains a large collection of image processing functions. In lots of cases, we have to use multiple functions, and passing images to other functions. Those functions perform computationally heavy task. We do not want to put additional stress to the processing system which is already experiencing huge stress.

Via a reference counting system, OpenCV's Mat (matrix) object can be shared and can be passed around without expensive copies (each Mat object has its own header, however the matrix may be shared between two instance of them by having their matrix pointers point to the same address). Whenever we copy a header of a Mat object, a counter is increased for the matrix. Whenever a header is cleaned this counter is decreased. When the counter reaches zero, the matrix is freed.

Note that the Mat's pointer is pointing to the headers of large matrix, not the data itself(i.e. the copy operators will only copy the headers). So, when we create Mat object, actually it is creating a head:

Mat imageA, imageB;

When we load an image, it's allocating memory for the matrix:

imageA = imread( argv[1], 1 );

Copy or assign:

imageC(image1);  // copy constructor
imageB = imageA; // assignment

After those operations, in the end, all images are pointing to the same single data matrix though their header parts are different.

Note that can create headers which refer to only a subsection of the full data. For example, to create a region of interest (ROI) in an image, we just create a new header with the new boundaries:

	
Mat imageD (imageA, Rect(10, 10, 150, 150) ); // a rectangle
Mat imageE = imageA(Range:all(), Range(2,5)); // row and column boundaries




Copying a Mat Object

We may want to copy the matrix itself, we can use clone() and copyTo() functions:

Mat imageB = imageA.clone();

Mat imageC;
imageA.copyTo(C);

Now modifying imageB or imageC will not affect the matrix pointed by the Mat header of imageA.





Summary

Here are what we've learned so far: The Basic Image Container.

  1. Output image allocation for OpenCV functions is automatic (unless specified otherwise).
  2. You do not need to think about memory management with OpenCVs C++ interface.
  3. The assignment operator and the copy constructor only copies the header.
  4. The underlying matrix of an image may be copied using the clone() and copyTo() functions.







Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







OpenCV 3 -

image & video processing



Installing on Ubuntu 13

Mat(rix) object (Image Container)

Creating Mat objects

The core : Image - load, convert, and save

Smoothing Filters A - Average, Gaussian

Smoothing Filters B - Median, Bilateral




Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong








OpenCV 3 image and video processing with Python



OpenCV 3 with Python

Image - OpenCV BGR : Matplotlib RGB

Basic image operations - pixel access

iPython - Signal Processing with NumPy

Signal Processing with NumPy I - FFT and DFT for sine, square waves, unitpulse, and random signal

Signal Processing with NumPy II - Image Fourier Transform : FFT & DFT

Inverse Fourier Transform of an Image with low pass filter: cv2.idft()

Image Histogram

Video Capture and Switching colorspaces - RGB / HSV

Adaptive Thresholding - Otsu's clustering-based image thresholding

Edge Detection - Sobel and Laplacian Kernels

Canny Edge Detection

Hough Transform - Circles

Watershed Algorithm : Marker-based Segmentation I

Watershed Algorithm : Marker-based Segmentation II

Image noise reduction : Non-local Means denoising algorithm

Image object detection : Face detection using Haar Cascade Classifiers

Image segmentation - Foreground extraction Grabcut algorithm based on graph cuts

Image Reconstruction - Inpainting (Interpolation) - Fast Marching Methods

Video : Mean shift object tracking

Machine Learning : Clustering - K-Means clustering I

Machine Learning : Clustering - K-Means clustering II

Machine Learning : Classification - k-nearest neighbors (k-NN) algorithm



Matlab Image and Video Processing



Vectors and Matrices

m-Files (Scripts)

For loop

Indexing and masking

Vectors and arrays with audio files

Manipulating Audio I

Manipulating Audio II

Introduction to FFT & DFT

Discrete Fourier Transform (DFT)



Digital Image Processing 2 - RGB image & indexed image

Digital Image Processing 3 - Grayscale image I

Digital Image Processing 4 - Grayscale image II (image data type and bit-plane)

Digital Image Processing 5 - Histogram equalization

Digital Image Processing 6 - Image Filter (Low pass filters)

Video Processing 1 - Object detection (tagging cars) by thresholding color

Video Processing 2 - Face Detection and CAMShift Tracking












Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master