AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Matlab 3d matrix to imagetype1/6/2024 I2 = double(img)/255 % Uint8 is converted to double, which is the same as im2double I1 = im2double(img) % Convert image to double precision type (0 ~ 1) Img = imread(‘./1.jpg’) % Read in is Unit8 (0 ~ 255) data Therefore, it is necessary to convert the image to double format before operation. The image data read by Matlab is uint8, and the values in MATLAB are usually stored and calculated by double (64 bit). One byte unsigned integer can only store 255 data at most, so it is easy to overflow the image operation 2. For example, if the pixel size of a color image is 400 * 300 (height * width), the saved data matrix is 400 * 300 * 3, where each color channel value is between 0 and 255 Function ‘*’ is not defined for values of class ‘uint8’ When it is an RGB image, it stores it in an 8-bit RGB matrix. In detail, imread stores gray-scale images in an 8-bit matrix. Compared with the default MATLAB data type, double precision floating-point double (64 bits, 8 bytes), it can naturally save a lot of storage space The image stored in this way is called 8-bit image. The data saved after reading pictures in MATLAB is uint8 (8-bit unsigned integer, i.e. MATLAB image type conversion and uint8, double, im2double, im2uint8 and mat2gray and other instructions – Thomas can write – CSDN blog 1. If it is not converted, the calculation will overflow I64 = double (I8)/255% uint is converted to double I2 = im2double (I1)% convert image I1 to double precision type (assuming graph matrix range 0-255) Therefore, it is necessary to convert the image to double format before operation, Therefore, the image data read in MATLAB is uint8, and the values in MATLAB are generally stored and calculated in double (64 bit). When it is an RGB image, it is stored in an 8-bit RGB matrix Imread stores gray images in an 8-bit matrix. In order to save storage space, matlab provides a special data type uint8 (8-bit unsigned integer) for image, and the image stored in this way is called 8-bit image MATLAB image processing on Unit8_ Baidu Knows Imshow pictures in MATLAB should be converted into uint8: 1 If you do this instead, you'll see that we get the same answer.The image pixel data is processed in MATLAB In the end, we will have a logical map where true are those locations that are neither equal to 1, 2, 3, 4 or 5. If you don't like the permute and bsxfun approach, one way would be to have a for loop and with an initially all true array, keep logical ANDing the final result with a logical map that consists of those locations which are not equal to each value in x. You can most certainly see that those elements that are neither 1, 2, 3, 4 or 5 get set to 10. All you have to do is change the input list at the beginning line of the code, and bsxfun, permute and any should do the work for you.īy using the code above, the output we get is: It prevents having messy logical indexing syntax, like img(img ~= 1 & img ~= 2 &. The advantage of the above method is that the list you want to use to check for the elements can be whatever you want. We can ensure this by casting the vector to be the same class as img. One thing we need to consider is that the image type and the vector x must be the same type. The last step would be to take this logical map, which that tells you the locations that are none of 1, 2, 3, 4, or 5 and we'd set those locations to 10. Once you finish this, we can use an all call operating on the third dimension to consolidate the pixel locations that are not equal to all of 1, 2, 3, 4 or 5. The first slice would give you the locations that don't match x = 1, the second slice would give you the locations that don't match x = 2, and so on. Each slice would tell you whether the locations in the image do not match an element in x. We can create a 3D column vector that consists of the elements of, then use bsxfun with the not equals method ( on your image (assuming grayscale) so that we thus create a 3D matrix of 5 slices. You can achieve this very easily with a combination of permute and bsxfun.
0 Comments
Read More
Leave a Reply. |