图像的中值滤波,就是在以某一像素为中心的n阶像素矩阵中,找出R、G、B各分量的中间值来分别替代该像素的RGB值,从而达到对图像噪声滤波的目的。这里的中间值并非像素矩阵R、G、B各分量的的算术平均值,而是像素矩阵R、G、B各分量排序后的中位数值。
下面是Delphi图像中值滤波的实现代码:
过程定义:
// 中值滤波。Size应为奇数
procedure ImageMedianValues(Data: TImageData; Size: LongWord);
实现代码:
procedure ImageMedianValues(Data: TImageData; Size: LongWord);
var
matrixOffset, srcOffset, dstOffset: LongWord;
Width, Height: LongWord;
mSize, Count: LongWord;
src: TImageData;
Top, Last, Median: PLongWord;
Colors: array of LongWord;
procedure AssortValue;
asm
mov ah, [esi]
mov al, [esi + 4]
mov dl, [esi + 8]
cmp ah, al
jae @@1
xchg ah, al
@@1:
cmp ah, dl
jae @@2
xchg ah, dl
@@2:
cmp al, dl
jbe @@3
xchg al, dl
@@3:
mov [edi], ah
mov [edi + 4], dl
mov [edi + 8], al
inc esi
inc edi
end;
procedure GetValue;
asm
mov ah, [esi]
mov dh, [esi + 4]
mov dl, [esi + 16]
mov al, [esi + 8]
cmp ah, [esi + 12]
jbe @@1
mov ah, [esi + 12]
@@1:
cmp ah, [esi + 24]
jbe @@2
mov ah, [esi + 24]
@@2:
cmp dh, dl
jae @@3
xchg dh, dl
@@3:
cmp dh, [esi + 28]
jae @@4
xchg dh, [esi + 28]
@@4:
cmp dl, [esi + 28]
jae @@5
mov dl, [esi + 28]
@@5:
cmp al, [esi + 20]
jae @@6
mov al, [esi + 20]
@@6:
cmp al, [esi + 32]
jae @@7
mov al, [esi + 32]
@@7:
cmp ah, al
jae @@8
xchg al, ah
@@8:
cmp ah, dl
jae @@9
xchg ah, dl
@@9:
cmp al, dl
jae @@10
mov al, dl
@@10:
mov
1.[Error] DCansactionIformationManagement.pas(171): String literals may have at most 255 elements
[Fatal Error] DCMain.pas(32): Could not compile used unit 'DCansactionIformationManagement.pas'
报错:‘不正常定义了参数。提供了不一致或不完整信息’
解决方法:语法
数据定义要一致
2. ......