Computer Vision si Procesare
Avansata de Imagini
in Medii Virtuale Distribuite
Adrian DARABANT
L3
Matrices and ROI
• Creating a region of Interest
– Mat A – load an image
– Mat B = Mat(A, Rect(x,y, width, height));
• B does not have its own copy of data – i.e data
is shared.
• Image operations on B will perform on the ROI
Matrices
• Create
– Mat M(2,2, CV_8UC3, Scalar(0,0,255));
– Mat::eye(4,4, CV_8U) //identity
– Mat::ones(2, 2, CV_32F); // matrix of ones
– Mat::zeros(3,3, CV_8UC1);
– Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1,
0, -1, 0);
• Display
– cout<<A<<endl // where A is a matrix
Image Addition
• Combine 2 images
• Mat A, B, C; C=A+B ?? Or
• void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1
Averaging Images
• Improve image quality –for registered images
5 10
20 50 100
Substraction
C(i,j) = A(i,j) –B(i,j) – detect change in sequence of
images
Multiplication
• Adjust brightness/contrast
X2
Remarks
• Arithmetic operation can produce pixel values
outside of the range [0 – 255].
• You should convert values back to the range
[0 – 255] to ensure that the image is displayed
properly.
• How would you do the following mapping?
[fmin – fmax] [ 0 – 255]
Operations on Binary Images
• What is a binary Image ? Bitwise
• Unary – Image operator scalar
• Binary – Image1 operator Image2
And
• Usually used to mask out part of the image
C = A &B
• Add parts of the image (combine)
C= A | B
Example
Result of AND Result of OR
OR
Image Filtering
• Perform linear & non-linear operations on 2D
images
– Linear filters – weighted sum(neigh pixel values)
– Morphological filters – min/max(neigh pixel
values)
– Usually neighborhood pixels are those covered by
a kernel (ex. matrix 3x3)
– Image borders ? Replicated or zero
Blur/Smooth
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int
borderType=BORDER_DEFAULT )
void GaussianBlur( src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=
InputArray
BORDER_DEFAULT )
void medianBlur( InputArray src, OutputArray dst, int ksize)
void boxFilter( src, OutputArray dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), bool
InputArray
normalize=true, int borderType=BORDER_DEFAULT )
Erosion