图像相似度比较(phash算法的halcon实现)

 自定义算子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])

 

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值