이미지 조각별 선형 변환

  이미지 조각별 선형 변환(Piecewise Linear Transformation)은 서로 다른 영역의 픽셀 값에 서로 다른 선형 변환을 적용하여 이미지의 대비와 밝기를 조정하는 이미지 처리 기술입니다. 이는 이미지의 특정 영역의 세부 묘사를 향상시키거나 이미지의 전체적인 모양을 조정하는 데 자주 사용됩니다. 수학적으로 조각별 선형 변환은 다음 형식으로 표현될 수 있습니다.
  입력 이미지의 각 픽셀 포인트 (x, y) (x, y) 에 대해( 엑스 ,y ) , 출력 값f ′ ( x , y ) f'(x, y)에프' (x,y )可以通过以下分段线性函数来计算:
f ′ ( x , y ) = { a 1 ⋅ f ( x , y ) + b 1 , if f ( x , y ) < x 1 a 2 ⋅ f ( x , y ) + b 2 , x 1 ≤ f ( x , y ) < x 2 ⋮ an ⋅ f ( x , y ) + bn 인 경우 xn − 1 ≤ f ( x , y ) < xn f'(x, y) = \begin{cases} a_1 \cdot f(x, y) + b_1, & \text{if } f(x, y) < x_1 \\ a_2 \cdot f(x, y) + b_2, & \ 텍스트{if } x_1 \leq f(x, y) < x_2 \\ \vdots \\ a_n \cdot f(x, y) + b_n, & \text{if } x_{n-1} \leq f(x , y) < x_n \\ \end{cases}에프' (x,y )= 1에프 ( 엑스 ,y )+1,2에프 ( 엑스 ,y )+2,에프 ( 엑스 ,y )+,만약  f ( x ,y )<엑스1만약  x 라면1에프 ( 엑스 ,y )<엑스2만약  x 라면n 1에프 ( 엑스 ,y )<엑스
  그 중, f ( x , y ) f(x, y)에프 ( 엑스 ,y ) 는 원본 이미지의 픽셀 포인트(x, y) (x, y)( 엑스 ,y ) 회색 값,( x 1 , x 2 , … , xn ) (x_1, x_2, \ldots, x_n)( x1,엑스2,,엑스) 는 분할 지점입니다.( a 1 , a 2 , … , an ) (a_1, a_2, \ldots, a_n)( _1,2,,) 는 기울기입니다.( b 1 , b 2 , … , bn ) (b_1, b_2, \ldots, b_n)( 1,2,,) 는 절편입니다.
  다음은 이미지의 조각적 선형 변환을 위해 OpenCV 라이브러리를 사용하는 Python 코드의 예입니다.

import cv2
import numpy as np

def piecewise_linear_transform(image, breakpoints, slopes, intercepts):
    # 创建一个空白图像,用于存储变换后的结果
    transformed_image = np.zeros_like(image)

    for i in range(len(breakpoints) + 1):
        lower_bound = breakpoints[i - 1] if i > 0 else 0
        upper_bound = breakpoints[i] if i < len(breakpoints) else 255

        # 对当前分段内的像素应用线性变换
        mask = (image >= lower_bound) & (image < upper_bound)
        transformed_image[mask] = slopes[i] * image[mask] + intercepts[i]

    return transformed_image

# 读取图像
input_image = cv2.imread('input.jpg', cv2.IMREAD_GRAYSCALE)

# 定义分段点、斜率和截距
breakpoints = [100, 150]
slopes = [1.5, 0.7, 1.2]
intercepts = [-100, 50, 0]

# 应用分段线性变换
output_image = piecewise_linear_transform(input_image, breakpoints, slopes, intercepts)

# 显示原始图像和变换后的图像
cv2.imshow('Original Image', input_image)
cv2.imshow('Transformed Image', output_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

Ich denke du magst

Origin blog.csdn.net/qq_50993557/article/details/132153227
Empfohlen
Rangfolge