Debug: more than 255 processing the image data overflow Matlab

wrong description

When image processing is performed using Matlab, a discovery data will overflow more than 255, 255 is maximum.
Error Screenshot

Error reason

Matlab stored picture data is read after uint8 type (in the range 0 to 255) , but when the image matrix operation, the data type is of type double . If the type of data used uint8 matrix operation, once the data beyond 255 will overflow.

Solution

  1. The read image data is converted to a double conversion result value I is located in [0,255]. 【recommend】
  2. Use im2double () conversion, the conversion result value I is located in [0,1].
    At this time, image processing is completed, to be used im2uint8 () or uint8 (round (I * 255) ) the gray value range of the image data back to [0, 255].
  3. The read image data into uint16 type , the conversion result value I is located in [0,255].

The benefits of using double the following two types:
① part function only supports double.
② the image data to ensure the accuracy of operation, to prevent data overflow.

Published 18 original articles · won praise 40 · views 50000 +

Guess you like

Origin blog.csdn.net/seawaysyyy/article/details/103489347