1. 程式人生 > >matlab怎麼將一個矩陣轉化為灰度圖

matlab怎麼將一個矩陣轉化為灰度圖

用三個函式即可,第一個函式imagesc()、第二個colormap()函式、第三個函式為flipud函式(): imagesc(A)將矩陣A中的元素數值按大小轉化為不同顏色,並在座標軸對應位置處以這種顏色染色。 colormap(gray)將矩陣A的顏色圖轉化為灰度圖,此時矩陣中值越小,灰度越黑;正常情況下,是矩陣值越大,灰度越黑,此處用flipud函式處理一下即可; 例項: A=[ 1.00 0.96 0.98 0.88 0.94 0.61 0.96 0.80 0.98 0.89 0.96 1.00 0.94 0.90 0.95 0.71 0.96 0.83 0.90 0.88 0.98 0.94 1.00 0.84 0.91 0.54 0.93 0.73 0.97 0.90 0.88 0.90 0.84 1.00 0.89 0.85 0.94 0.94 0.80 0.82 0.94 0.95 0.91 0.89 1.00 0.72 0.94 0.84 0.90 0.90 0.61 0.71 0.54 0.85 0.72 1.00 0.74 0.90 0.48 0.64 0.96 0.96 0.93 0.94 0.94 0.74 1.00 0.90 0.92 0.87 0.80 0.83 0.73 0.94 0.84 0.90 0.90 1.00 0.70 0.75 0.98 0.90 0.97 0.80 0.90 0.48 0.92 0.70 1.00 0.85 0.89 0.88 0.90 0.82 0.90 0.64 0.87 0.75 0.85 1.00]; mat = A; %# A n-by-n matrix of random values from 0 to 1 imagesc(mat); %# Create a colored plot of the matrix values colormap(flipud(gray)); %# Change the colormap to gray (so higher values are %# black and lower values are white) 執行結果圖:

在這裡插入圖片描述 感覺有用請點喜歡