import numpy as np
import cv2

def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2

    for i in range(center, rows-center):
        for j in range(center, cols-center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]   # 최소 or 최대
    return dst

image = cv2.imread("images/aircraft.jpg", cv2.IMREAD_GRAYSCALE)
if image is None:
    raise Exception("영상파일 읽기 오류")

minfilter_img = minmax_filter(image, 3, 0)  # 3 x 3 마스크 최솟값 필터링
maxfilter_img = minmax_filter(image, 3, 1)  # 3 x 3 마스크 최댓값 필터링

cv2.imshow("image", image)
cv2.imshow("minfilter_img", minfilter_img)
cv2.imshow("maxfilter_img", maxfilter_img)
cv2.waitKey(0)
ff2b18b7e4afa7b3939189700c91896f6061f527
<mask token>


def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2
    for i in range(center, rows - center):
        for j in range(center, cols - center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]
    return dst


<mask token>

<mask token>


def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2
    for i in range(center, rows - center):
        for j in range(center, cols - center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]
    return dst


<mask token>
if image is None:
    raise Exception('영상파일 읽기 오류')
<mask token>
cv2.imshow('image', image)
cv2.imshow('minfilter_img', minfilter_img)
cv2.imshow('maxfilter_img', maxfilter_img)
cv2.waitKey(0)

<mask token>


def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2
    for i in range(center, rows - center):
        for j in range(center, cols - center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]
    return dst


image = cv2.imread('images/aircraft.jpg', cv2.IMREAD_GRAYSCALE)
if image is None:
    raise Exception('영상파일 읽기 오류')
minfilter_img = minmax_filter(image, 3, 0)
maxfilter_img = minmax_filter(image, 3, 1)
cv2.imshow('image', image)
cv2.imshow('minfilter_img', minfilter_img)
cv2.imshow('maxfilter_img', maxfilter_img)
cv2.waitKey(0)

import numpy as np
import cv2


def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2
    for i in range(center, rows - center):
        for j in range(center, cols - center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]
    return dst


image = cv2.imread('images/aircraft.jpg', cv2.IMREAD_GRAYSCALE)
if image is None:
    raise Exception('영상파일 읽기 오류')
minfilter_img = minmax_filter(image, 3, 0)
maxfilter_img = minmax_filter(image, 3, 1)
cv2.imshow('image', image)
cv2.imshow('minfilter_img', minfilter_img)
cv2.imshow('maxfilter_img', maxfilter_img)
cv2.waitKey(0)

import numpy as np
import cv2

def minmax_filter(image, ksize, mode):
    rows, cols = image.shape[:2]
    dst = np.zeros((rows, cols), np.uint8)
    center = ksize // 2

    for i in range(center, rows-center):
        for j in range(center, cols-center):
            y1, y2 = i - center, i + center + 1
            x1, x2 = j - center, j + center + 1
            mask = image[y1:y2, x1:x2]
            dst[i, j] = cv2.minMaxLoc(mask)[mode]   # 최소 or 최대
    return dst

image = cv2.imread("images/aircraft.jpg", cv2.IMREAD_GRAYSCALE)
if image is None:
    raise Exception("영상파일 읽기 오류")

minfilter_img = minmax_filter(image, 3, 0)  # 3 x 3 마스크 최솟값 필터링
maxfilter_img = minmax_filter(image, 3, 1)  # 3 x 3 마스크 최댓값 필터링

cv2.imshow("image", image)
cv2.imshow("minfilter_img", minfilter_img)
cv2.imshow("maxfilter_img", maxfilter_img)
cv2.waitKey(0)