Double im2double Mat2gray One of two said

Source: Internet
Author: User

Reference: http://www.ilovematlab.cn/thread-61626-3-1.html
http://blog.csdn.net/u010159842/article/details/52523520 Preface

Tip: The first thing we need to know is that if you want to define a matrix in the console, then it's a double type of matrix and not I take it for granted that it's uint8 type.

A =[235]
whos a
Double

The double () function simply converts the data to a double type, that is, if the type of uint8 is simply converting it to a double type, you can intuitively understand it by adding a decimal point and 0 directly behind the uint8, such as 302- 302.0000 This form, of course, is only for the convenience of memory. im2double

And for the im2double () function, it's a little different, one of which is the same as double () and the data into a double type, but there are two things to say. (1) When the input data type itself is a double type, at this point the im2double () function has little effect and returns the same result as the original matrix. (2) When the input data type is uint8, the result of the return value is a double type data between [0,1]. Take this result out and think about it as a double (input result)/255; This also validates what others say: According to 0–>>0 (0/255=0), 255–>>1 (255/255=1), the value is proportionally processed into a double value between 0~1

% using the system function im2double
A = Uint8 ([1 2 3 4 5]);
tran_1 = im2double (A);
% use your own method/255 get
tran_2 = double (A)/255
Mat2gray

The Mat2gray () function is similar to im2double (), but it is different, although the data for both is between [0,1], but Mat2gray () is the result of the normalization of the input data.
The input data is –>>0; the maximum value by the minimum value –>>1 and the output type is double. In other words, the result of the Mat2gray () conversion must be 0, 12 digits. but IM
2double () does not necessarily exist, only if there is 0,255 in its input data. And it is normalized regardless of whether the input data is a uint8 or a double type.

Tran_3 =mat2gray (A);
the principle of Mat2gray

What is the principle of the Mat2gray? See a person's blog so write out the algorithm flow. So I wrote a small program to verify the next, and sure enough is to use the normalization of the x= (x-min)/(max-min) this formula.
Algorithm Flow:
1. Calculates the inverse of the difference between the maximum and minimum values: det=1/(max (f)-min (f));
2, for data F intermediary between the maximum value and the minimum value of the data is such processing using temp_last= (Temp1-min (F)) *det can be.

% defines a validation vector
a = [1 4 8 each];
% found maximum
max_1 = max (a);
min_1 = min (a);
% normalized
det = 1/(max_1-min_1);
b = (a-min_1) *det;

C =mat2gray (a);
% comparison result
difference = SUM (B-C);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.