灰度圖像反轉:
灰度圖的灰度值范圍一般從0到255,白色為255,黑色為0,故黑白圖片也稱灰度圖像。灰度反轉是指對圖像灰度范圍進行線性或非線性取反,產生一幅與輸入圖像灰度相反的圖像。
假設一點的灰度值為f(x,y),那么反轉后就是255-f(x,y)。
1、Matlab實現
使用matlab驗證灰度反轉。

%-------------------------------------------------------------------------- % 灰度圖像反轉 %-------------------------------------------------------------------------- clc; clear all; RGB = imread('G:\test\AC6102_UART_TFT50_IMG\1\image.bmp'); %讀取圖像 gray = rgb2gray(RGB); %灰度圖 inve1 = imcomplement(gray); %函數法圖像反轉 inve2 = 255 - gray; %公式法圖像反轉 subplot(3,1,1);imshow(gray); title('灰度圖像'); subplot(3,1,2);imshow(inve1);title('函數法圖像反轉'); subplot(3,1,3);imshow(inve2);title('公式法圖像反轉');
代碼分別從函數法和公式法,實現了灰度圖像的反轉。這個灰度圖像是從上一次實驗提取Y分量得到的。
2、fpga實現
這里就是將上次Y2直接輸出灰度圖像的,這里使用公式法將灰度圖像反轉再輸出。結果與matlab一樣。
彩色圖像反轉:
1、matlab實現:

%-------------------------------------------------------------------------- % 彩色圖像反轉 %-------------------------------------------------------------------------- clc; clear all; RGB = imread('G:\test\1\image.bmp'); %讀取圖像 inve1 = imcomplement(RGB); %函數法圖像反轉 inve2 = 255 - RGB; %公式法圖像反轉 subplot(3,1,1);imshow(RGB); title('原圖'); subplot(3,1,2);imshow(inve1);title('函數法圖像反轉'); subplot(3,1,3);imshow(inve2);title('公式法圖像反轉');
matlab驗證結果:
2、fpga實現:
由此可見,fpga實現的效果與matlab實現的效果一致。