Chapter 3, Array and Matrix Operations

  1. Which of the element-wise mathematical operations and bitwise operations would produce the exact same results?

The bitwise_xor and absdiff functions would produce the same result.

  1. What is the purpose of the gemm function in OpenCV? What is the equivalent of AxB with the gemm function?

The gemm function is the generalized multiplication function in OpenCV. Here's the gemm function call equivalent to the simple multiplication of two matrices:

gemm(image1, image2, 1.0, noArray(), 1.0, result);
  1. Use the borderInterpolate function to calculate the value of a non-existing pixel at point (-10, 50), with a border type of BORDER_REPLICATE. What is the function call required for such a calculation?
Vec3b val = image.at<Vec3b>(borderInterpolate(50,
image.rows,
cv::BORDER_REFLECT_101),
borderInterpolate(-10,
image.cols,
cv::BORDER_WRAP));
  1. Create the same identity matrix in the Identity matrix section of this chapter, but use the setIdentity function instead of the Mat::eye function.
Mat m(10, 10, CV_32F);
setIdentity(m, Scalar(0.25));
  1. Write a program using the LUT function (a look-up table transformation) that performs the same task as bitwise_not (invert colors) when executed on grayscale and color (RGB) images.
Mat image = imread("Test.png");

Mat lut(1, 256, CV_8UC1);

for(int i=0; i<256; i++)
{
lut.at<uchar>(0, i) = 255 - i;
}

Mat result;
LUT(image, lut, result);
  1. Besides normalizing the values of a matrix, the normalize function can be used to brighten or darken images. Write the required function call to darken and brighten a grayscale image using the normalize function.
normalize(image, result, 200, 255, CV_MINMAX); // brighten
normalize(image, result, 0, 50, CV_MINMAX); // darken
  1. Remove the blue channel (the first channel) from an image (a BGR image created using the imread function) using the merge and split functions.
vector<Mat> channels;
split(image, channels);
channels[0] = Scalar::all(0);
merge(channels, result);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.187.108