%%%%%%%%%%%%%%% Data Type%%%%%%%%%%%%%%%%%%%%type conversion Clear Clca=3.14%default is Doublewhosa=uint8 (a)%type conversion, fractional part rounding a=[1.1,2.1,3.1;4.1,5.1,6.5;7.6,8.7,9.7]a=uint8 (A)%As with matrices, you can%%im2uint8 Image Clc;cleara= [-0.5 0.5 0.75 1.5] G1= Im2uint8 (A)%the minimum value of F1 is 0 and the maximum value is 255F2= Uint8 (A)%type conversion rounding, negative number all returned to zero%%Im2doubleclccleara=uint8 ([0 127 255; - to the;1 2 3]) I=im2double (A) a zero-percent input is a matrix of uint8, and the output is from [0,255To0.0,1.0]a=[0 127 255; - to the;1 2 3]i=im2double (A)%the input is a doubel matrix and is output as-is. %%IM2BW Gray image becomes a two value image Clccleara=[0 1 0.1;0.4Pi0.5;0.51 0.41 0.39]BW= IM2BW (A)%default to 0.5, greater than logic 1, less than logic 0BW= IM2BW (A,0.4) %with 0.4 verdict, the output is the logical matrix BW= IM2BW (A,0.5) BW= IM2BW (A,1)%%Str2numclcclearstr2num ('123') Str2Num ('123 456') Str2Num (['1 2';'3 4'])%%mat2grayclose All;clear;clca=[0 1-0.1;0.4Pi0.5;0.51 0.41 0.39]k= Mat2gray (A)% is mapped from [Min, Max] to [0,1]i= Imread ('Rice.png'); J= Filter2 (Fspecial ('Sobel'), I); K=Mat2gray (j); Imshow (I), figure, Imshow (j); Figure,imshow (K)
Im2uint8,im2wb,mat2gray and other image data type conversion functions