2017-02-07 7 views
-4

私はこれらの2つの機能を終了しようとしていますが、誰かが私にそれを行う方法を示すことができる場合はどこから始めたらいいのですか?反射境界と相互相関2Dをどのように定義しますか?

def padReflectBorder(image, N): 

    """This function pads the borders of the input image by reflecting the 
    image across the boundaries. 

    N is the number of rows or columns that should be added at each border; 
    i.e., the output size should have 2N more rows and 2N more columns than 
    the input image. 

    The values in the input image should be copied to fill the middle of the 
    larger array, and the borders should be filled by reflecting the array 
    contents as described in the documentation for cv2.copyMakeBorder(). 

    This function should be equivalent to the library call: 

     cv2.copyMakeBorder(image, N, N, N, N, borderType=cv2.BORDER_REFLECT_101) 

    Note: BORDER_REFLECT_101 means that the values in the image array are 
      reflected across the border. Ex. gfedcb|abcdefgh|gfedcba 

    NOTE: You MAY NOT use any calls to numpy or opencv library functions, but 
      you MAY use array broadcasting and "advanced" numpy indexing 
      techniques for this function. 

    Parameters 
    ---------- 
    image : numpy.ndarray(dtype=np.uint8) 
     A grayscale image represented in a numpy array. 

    N : int 
     An integer strictly greater than zero and less than the smallest 
     dimension of the input image representing the number of padding pixels 
     to add at each border. 

    Returns 
    ------- 
    numpy.ndarray(dtype=np.uint8) 
     A copy of the input array with 2N additional rows and columns filled 
     with the values of the input image reflected over the borders. 
    """ 

def crossCorrelation2D(image, kernel): 

    """This function uses native Python code & loops to compute and return the 
    valid region of the cross correlation of an input kernel applied to each 
    pixel of the input array. 

    NOTE: Lectures 2-05, 2-06, and 2-07 address this concept. 

    Recall that for an image F and kernel h, cross correlation is defined as: 

     G(i,j) = sum_u=-k..k sum_v=-k..k h[u,v] F[i+u,j+v] 

    For N = kernel.shape[0] // 2, this function should be equivalent to: 

     cv2.filter2D(image, cv2.CV_64F, kernel)[N:-N, N:-N] 

    See http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html#filter2d 
    for details. 

    Your code must operate on each pixel of the image and kernel individually 
    for each step of the computation. (We know this is inefficient, but we want 
    to make sure that you understand what is really happening within the more 
    efficient library functions that are available.) 

    NOTE: You MAY NOT use any numpy, scipy, or opencv library functions, 
      broadcasting rules, or "advanced" numpy indexing techniques, nor may 
      you use the operator functions or convolution functions listed in the 
      note at the top. You MUST manually loop through the image at each 
      pixel. (Yes, we know this is slow and inefficient.) 

    NOTE: You MAY assume that kernel will always be a square array with an odd 
      number of elements. 

    Parameters 
    ---------- 
    image : numpy.ndarray(dtype=np.uint8) 
     A grayscale image represented in a numpy array. 

    kernel : numpy.ndarray 
     A kernel represented in a numpy array of size (k, k) where k is an odd 
     number strictly greater than zero. 

    Returns 
    ------- 
    output : numpy.ndarray(dtype=np.float64) 
     The output image. The size of the output array should be smaller than 
     the original image size by k-1 rows and k-1 columns, where k is the 
     size of the kernel. 
    """ 

答えて

4

これは宿題のようです。実際、私はそれを知っているので、私はそれを書いたTAです。

crossCorrelation2D関数のdocstringのリファレンスセクションが欠落しているようです(「講義2-05、2-06、および2-07」を参照)。それはおそらくそこから始めることをお勧めします。これは、各機能の目的を理解し、割り当てを完了するための準備に役立ちます。

どちらの関数でも、イメージを読み取り、ドキュメントストリングに記述されているライブラリ関数を呼び出すコードを書くと便利です。関数はそれらのライブラリ呼び出しと同等でなければならないので、cv2.copyMakeBorder関数とcv2.filter2D関数の出力は、あなたが生成すると思われるものを示しているはずです。

これらの手順を完了したら、関数を自分で作成する際に問題が生じることがあります。あなたのコードをチェックするためにいくつかの単体テストを書くことができ、作業のフィードバックのために格付けサーバに提出することができます。

まだ問題が解決しない場合は、コースフォーラムやスラックチャンネルでクラスメートに助けを求めるか、私と他のTAさんを見て助けを求めることができます。

運が良かった!

関連する問題