This task is to get a few raw pictures, no other header files or information, need to use python to open and display the raw pictures
(As a beginner, I worked on jpg and png all day, and suddenly came a raw, which means I am very big)
Open the display through a third party, find its information, record it, and use it later
Forget all kinds of raw to jpg images searched on the Internet, I tried one or two, but they all failed
Two methods are recommended here. One is software: ps. Using ps, you can directly open and read raw pictures. When opened, it will automatically display the height, width, number of channels and digits (but for now, it feels like ps is random.Match the width and length, the displayed picture is not accurate), as shown below, can also be converted to other formats if necessary, such as jpg, png, etc.
Another option is an online website: Photopea | Online Photo Editor
Super easy to use!!!And you can choose a variety of matching forms, you can also preview the picture, and then you can choose the correct matching form, the corresponding height and width and other information is corresponding to your picture
(usually very useful, you can perform various image processing operations, if the demand is not large, you don't need ps)
With the number of high and wide channels, we can perform numpy image analysis, and finally read the image through opencv
import numpy as npimport cv2# Note that this function can only display data of type uint16. If it is data of uint8, please convert it to uint16 first.Otherwise, there will be problems with the picture display.**# image is of array type, it doesn't matter how many dimensions, directly operate all elementsimg = np.fromfile("D:/VScode/pyproject/PR/view/showRaw/1.raw", dtype=np.uint16)print(img)print("Total number of array elements: ",img.size) #Print the size of the array, that is, the total number of array elements# /mean, standard deviation normalization/image = (img - np.average(img)) / np.std(img)# ///print(image)imgData = image.reshape(288, 384, 1)# show imagecv2.imshow('img', imgData)cv2.waitKey()cv2.destroyAllWindows()
I have used some image normalization methods. I have a general understanding of the following three commonly used methods. You can try them according to your own pictures. My own image normalization effect is better this time.is the mean and standard deviation normalization
#/"x-min/max-min"//image = (img - np.min(img)) / (np.max(img) - np.min(img))# ///# ///simoid normalization/image = imgfor i in range(size):image[i] = 1.0 / (1 + np.exp(-float(img[i])))# ///# /mean, standard deviation normalization/image = (img - np.average(img)) / np.std(img)# ///
①np.fromfile
The raw image can be read and converted into a vector array, which is convenient for us to process later
imgData2 = np.fromfile('D:/VScode/pyproject/PR/view/showRaw/2.raw', dtype='uint16')
②np.average: take the average, the difference between np.mean and this is that average can be weighted average
③np.std: to standard deviation
④np.random.randint(0,10,(4,3)): Randomly generate a 4x3 matrix in 0-10
⑤ np.hstack: vector stitching, raw image numpy read out in vector form, need to use
⑥np.concatenate((a, b), axis=1): The ab matrix is concatenated in the form of columns, and one more column is added
rotation = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]])trans = np.array([[7],[8],[0]])z = np.concatenate((rotation, trans), axis=1)
[[1 2 3 7][4 5 6 8][7 8 9 0]]
①image.shape: Display the number of image height and width channels
②image.size: length of image data
③image[y:y+h,x:x+w]: the interception of the image, xy is the starting point of the upper left corner of the intercepted image
What I have described so far are some records of individuals in the process of learning neural networks. They are for reference only. If there is any error, please correct me in the comment area, thank you!!!