使用礼帽变换时如何旋转结构元素?

我正在对图像实施礼帽式转换,结构元素长21像素,宽度1像素,如何旋转该结构元素?因此,我可以从该图像中提取不同角度的信息。

我现在拥有的是

class Base {
public:
    Base( Base *parent = nullptr ) {
        if ( parent ) 
            parent->addChild( this );
    }
    virtual ~Base() {
        for ( Base *child : children ) 
            delete child;
    }
private:
    void addChild( Base *child ) {
        children.push_back( child );
    }
    std::vector<Base*> children;
};

class Derived : public Base {
public:
    Derived( Base *parent = nullptr ) : Base( parent ) {}
}

但是如何将其应用于不同的角度呢?就像将结构元素旋转30度一样。

controlcls 回答:使用礼帽变换时如何旋转结构元素?

我用来旋转结构元素的函数如下:

import cv2 
import numpy
def rotate_bound(image,angle):
    (h,w) = image.shape[:2]
    (cx,cy) = (w/2,h/2)

    M = cv2.getRotationMatrix2D((cx,cy),-angle,1.0)
    print(M.shape)
    print(M)

    cos = np.abs(M[0,0])
    sin = np.abs(M[0,1])

    nW = int((h*sin)+(w*cos))
    nH = int((h*cos)+(w*sin))

    M[0,2] += (nW/2) - cx
    M[1,2] += (nH/2) - cy

    return cv2.warpAffine(image,M,(nW,nH))

element = np.ones((21,1))
rotated_element = rotate_bound(element,30)
rotated_element[rotated_element == 0] = 10
result = cv2.morphologyEx(image,cv2.MORPH_TOPHAT,rotated_element)

感谢@ fmw42的帮助:)

本文链接:https://www.f2er.com/3144031.html

大家都在问