This is the first day of my participation in Gwen Challenge

Basic knowledge of

Let’s start with the structure. The structure of an image is divided into file identifiers and data blocks, as shown in the following figure

The file identifier contains important information such as the file signature, dimension, height, width, depth, number of channels, color format, start address, end address, and amount of data.

So the question is, what is the width and height of a 512Bytes 16-bitmap square image, and what is the range of pixels if they are integers?

Here comes an important concept, image depth. The so-called image depth refers to the number of bits occupied by each pixel. When a pixel occupies more pixels, we can feel that the color of this place is more bright, and we often say that the gray processing image after normalization is called to reduce the pixel value.

Now come back and look at our problem again. We know that the width and height are the same. Assume an 8-bit color, 512/16 * 8=256. The value range is 2 ^ 8,0~256. At this point, our image pixel value matrix, for example, looks like the following (example specific specified data, not actual data):

If we can shrink the original image down to 44, will we have compressed the storage space? So how do we calculate that? The formula is divided into a region according to MN, and each pixel value is vector, and vector sum is carried out, i.e., X1+X2+…. +X(MN) and divide the sum of the vectors by the current number of bitmaps, X1+X2+…. +X(MN))/16; (67+187+56+ 198+77+8+28+188+168+213+140+189+231+67+204+20)/16 is approximately the same integer 127

Practice – Zoom images using OpenCV

Void resize(InputArray shur, OutputArray DST, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR ) Namely, input matrix and output matrix, the size of the output image (note: when this value is 0, the fx, fy not 0) at the same time, the X-axis scaling factor, the Y-axis scaling factor, the interpolation method (defaults to a linear interpolation, can choose a nearest neighbor interpolation, interpolation, cubic spline interpolation, interpolation Lanczos)) this case algorithm based on linear interpolation on the scene The code is as follows:

Mat inImage = imread(" case input.jpg"); Mat tmpImage,outImage; tmpImage=inImage; Imshow (" Input original image ", inImage); The resize (tmpImage outImage, Size (4, 4), (0, 0), (0, 0)); Imshow (" Zoomed image ", outImage);Copy the code