Cython—基于区域的对比度—图像分割的区域对比度计算

编程入门 行业动态 更新时间:2024-10-06 04:01:56

Cython—基于区域的<a href=https://www.elefans.com/category/jswz/34/1750444.html style=对比度—图像分割的区域对比度计算"/>

Cython—基于区域的对比度—图像分割的区域对比度计算

文章目录

          • 代码一
          • 代码二
          • 测试代码

这是基于区域的对比度的显著性检测代码, 【关于原文请查看】
关于图像分割的区域对比度计算:

  1. 计算区域的中心与质心。关于计算前的分割区域
  2. 区域颜色相似度距离的高斯权重分布
  3. 生成新区域
  4. 统计区域边界的像素数量
  5. 形成分割区域

开发环境win10,Visual studio 2015

代码一
#%%cython --cplus --annotate
import numpy as np
cimport cython
cimport numpy as np
from cpython cimport array
from libc.math cimport pow
from libc.math cimport sqrt
from libc.math cimport exp
from libc.math cimport fabs
from libcpp.vector cimport vector
from scipy.spatial.distance import pdist,squareform@cython.boundscheck(False)
@cython.wraparound(False)
cpdef Build_Regions_Contrast(int regNum, np.ndarray[np.int32_t, ndim=2] regIdx1i,int[:,:] colorIdx1i, float[:,:,:]color3fv, float sigmaDist,float ratio,float thr):cdef:int height = regIdx1i.shape[0]int width = regIdx1i.shape[1]int colorNum = color3fv.shape[1]float cx = <float>width / 2.0float cy = <float>height / 2.0Py_ssize_t x = 0, y = 0, i=0, j=0, m=0, n=0, yi=0, xi=0,iii=0pixNum_np = np.zeros(regNum,dtype=np.int64)pixNum_np = np.bincount(regIdx1i.reshape(1, width * height)[0])ybNo_np = np.zeros(regNum, dtype=np.float64)regs_mX = np.zeros(regNum, dtype=np.float64)regs_mY = np.zeros(regNum, dtype=np.float64)regs_vX = np.zeros(regNum, dtype=np.float64)regs_vY = np.zeros(regNum, dtype=np.float64)freIdx_f64 = np.zeros((regNum, colorNum), dtype=np.float64)regColor_np = np.zeros((regNum, colorNum), dtype=np.int32)tile_pixNum = np.zeros((regNum, colorNum), dtype=np.int64)regs_np = np.zeros((regNum, 4), dtype=np.float64)cdef int [:,::1]regColor_view = regColor_npcdef double[:,::1]regs_view = regs_npwith nogil:for y in range(height):for x in range(width):regs_view[regIdx1i[y, x], 0] = fabs(x - cx)  # ad2c_0regs_view[regIdx1i[y, x], 1] = fabs(y - cy)  # ad2c_1regs_view[regIdx1i[y, x], 2] += x            # region center x coordinateregs_view[regIdx1i[y, x], 3] += y            # region center y coordinateregColor_view[regIdx1i[y, x], colorIdx1i[y, x]] += 1regs_np[:, 0] = np.divide(regs_np[:, 0], pixNum_np * width)regs_np[:, 1] = np.divide(regs_np[:, 1], pixNum_np * height)regs_mX = np.divide(regs_np[:, 2], pixNum_np)regs_mY = np.divide(regs_np[:, 3], pixNum_np)regs_np[:, 2] = np.divide(regs_mX, width)regs_np[:, 3] = np.divide(regs_mY, height)freIdx_f64 = regColor_np.astype(np.float64)tile_pixNum = np.tile(pixNum_np[:, np.newaxis], (1, colorNum))freIdx_f64 = np.divide(freIdx_f64, tile_pixNum)#==========================================================================================similar_dist = np.zeros((colorNum, colorNum), dtype=np.float64)similar_dist = squareform(pdist(color3fv[0]))rDist_np = np.zeros((regNum, regNum), np.float64)regSal1d_np = np.zeros((1, regNum), np.float64)cdef double[:,:]regs_view2 = regs_npcdef double[:]mX_view = regs_mXcdef double[:]mY_view = regs_mYcdef double[::1]vX_view = regs_vXcdef double[::1]vY_view = regs_vYcdef double[:,:]similar_dist_view = similar_distcdef double[:,::1]rDist_view = rDist_npcdef double[:,::1]regSal1d_view = regSal1d_npcdef double[:,:]freIdx_f64_view = freIdx_f64cdef long long[:]pixNum_view = pixNum_npcdef double dd_np &#

更多推荐

Cython—基于区域的对比度—图像分割的区域对比度计算

本文发布于:2024-03-14 05:15:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1735711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对比度   区域   图像   Cython

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!