自定义算子get_hash(ImageZoomok:::Phash)
*图像DCT过程
*参考 https://www.cnblogs.com/latencytime/p/10228938.html
*核心公式:F(u,v)= A f(x,y) AT
*ImageZoomok:为缩放到32*32的灰度图像
*Phash:为灰度图像计算出的Phash编码
*0.预处理
zoom_image_size(ImageZoomok, ImageZoomok, 32, 32, 'constant')
*1.创建A矩阵
*系数为cos((2x+1)*u*pi/(N*N))
gen_image_gray_ramp(ImageGrayRamp, 0, 1, 0, 0, 0, 32, 32)
get_region_points(ImageGrayRamp,Rows1, Columns1)
get_grayval(ImageGrayRamp, Rows1, Columns1, Grayval)
Grayval_A:=real(Grayval*2+1)*3.14/(2*32)
gen_image_gray_ramp(ImageGrayRamp, 1, 0, 0, 0, 0, 32, 32)
get_grayval(ImageGrayRamp, Rows1, Columns1, Grayval_u)
Grayval_A:=cos(Grayval_A*Grayval_u)*(sqrt(2.0/32))
create_matrix(32,32,0,A)
set_value_matrix(A, Rows1, Columns1, Grayval_A)
*2.获取图像矩阵
get_grayval(ImageZoomok,Rows1, Columns1,Grayval)
create_matrix(32,32,0,IMG)
set_value_matrix(IMG, Rows1, Columns1, Grayval)
*3.计算DCT图像
mult_matrix(A, IMG, 'AB',DCT)
mult_matrix(DCT, A, 'ABT',DCT)
get_full_matrix(DCT, Values)
gen_image_const(ImageDCT, 'real',32,32)
*4.计算phash指纹
set_grayval(ImageDCT, Rows1, Columns1, Values)
gen_rectangle1(Rectangle, 0, 0, 7, 7)
get_region_points(Rectangle, Rows2, Columns2)
get_grayval(ImageDCT,Rows2, Columns2, phashcode)
mean_phash:=mean(phashcode)
Phash:=[phashcode[>=]mean_phash]
return ()
比较两幅图phash编码的汉明距离
get_hash(ImageA, PhashA)
get_hash(ImageB, PhashB)
dist_ham:=sum([PhashA[!=]PhashB])