Python을 사용하여 이미지 색상을 일치시키는 방법
소개:
현대 사회에서 이미지 처리는 영화 특수효과, 의료 영상 진단 등 다양한 분야에서 널리 사용되고 있습니다. 그중에서도 이미지 색상 매칭은 서로 다른 사진 간의 색상을 일관되게 만들어 사용자 경험을 향상시킬 수 있는 중요한 기술입니다. 이 기사에서는 Python을 사용하여 이미지 색상을 일치시키는 방법을 소개하고 코드 예제를 통해 자세히 설명합니다.
1. 종속 라이브러리 설치
시작하기 전에 Python 환경과 PIL 라이브러리(Python Imaging Library)가 설치되어 있는지 확인해야 합니다. PIL 라이브러리가 설치되어 있지 않은 경우 다음 명령으로 설치할 수 있습니다.
pip install pillow
2. 이미지 데이터 읽기
먼저 일치시킬 이미지와 참조 이미지의 데이터를 읽어서 PIL로 변환해야 합니다. 작동 가능한 데이터 구조. 두 개의 사진이 있다고 가정합니다. image.jpg
是待匹配的图片,reference.jpg
는 참조 사진입니다. 코드 예제는 다음과 같습니다.
from PIL import Image def read_image(filename): image = Image.open(filename) data = list(image.getdata()) width, height = image.size return data, width, height image_data, image_width, image_height = read_image('image.jpg') reference_data, reference_width, reference_height = read_image('reference.jpg')
3. 각 채널의 평균 및 표준 편차를 계산합니다.
색상 일치를 달성하려면 각 채널을 계산해야 합니다. - 일치하는 그림과 참조 그림. 채널의 평균 및 표준 편차. 코드 예시는 다음과 같습니다.
import numpy as np def calculate_mean_std(data): pixels = np.array(data, dtype=np.float32) mean = np.mean(pixels, axis=0) std = np.std(pixels, axis=0) return mean, std image_mean, image_std = calculate_mean_std(image_data) reference_mean, reference_std = calculate_mean_std(reference_data)
4. 색상 매칭
각 채널의 평균과 표준편차를 사용하여 색상 매칭을 위한 다음 공식을 사용할 수 있습니다.
matched_data = (image_data - image_mean) / image_std * reference_std + reference_mean
코드 예시는 다음과 같습니다.
def match_color(data, mean, std, reference_mean, reference_std): matched_data = np.array(data, dtype=np.float32) matched_data = (matched_data - mean) / std * reference_std + reference_mean matched_data = matched_data.clip(0, 255) return list(matched_data.astype(np.uint8)) matched_image_data = match_color(image_data, image_mean, image_std, reference_mean, reference_std)
5 . 일치 항목을 저장한 후
마지막으로 일치하는 이미지 데이터를 새 이미지 파일로 저장합니다. 코드 예제는 다음과 같습니다.
def save_image(data, width, height, filename): image = Image.new('RGB', (width, height)) image.putdata(data) image.save(filename) save_image(matched_image_data, image_width, image_height, 'matched_image.jpg')
결론:
위 단계를 통해 Python을 사용하여 이미지 색상을 일치시키는 방법을 배웠습니다. . 이 기술은 이미지 처리, 디자인 및 기타 분야에 폭넓게 적용되며 이미지의 품질과 일관성을 효과적으로 향상시킬 수 있습니다. 이 글이 여러분에게 도움이 되길 바라며, 실제 프로젝트에 적용해 보시기 바랍니다.
위 내용은 Python을 사용하여 이미지 색상을 일치시키는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

PythonlistsCanstoreAnyDatAtype, ArrayModuLearRaysStoreOneType 및 NUMPYARRAYSAREFORNUMERICALPUTATION.1) LISTSAREVERSATILEBUTLESSMEMORY-EFFICENT.2) ARRAYMODUERRAYRAYRAYSARRYSARESARESARESARESARESARESAREDOREDORY-UNFICEDONOUNEOUSDATA.3) NumpyArraysUraysOrcepperperperperperperperperperperperperperperperferperferperferferpercient

whenyouattempttoreavalueofthewrongdatatypeinapythonaphonarray, thisiSdueTotheArrayModule의 stricttyPeenforcement, theAllElementStobeofthesAmetypecified bythetypecode.forperformancersassion, arraysaremoreficats the thraysaremoreficats thetheperfication the thraysaremorefications는

Pythonlistsarepartoftsandardlardlibrary, whileraysarenot.listsarebuilt-in, 다재다능하고, 수집 할 수있는 반면, arraysarreprovidedByTearRaymoduledlesscommonlyusedDuetolimitedFunctionality.

thescriptIsrunningwithHongpyThonversionDueCorRectDefaultTerpretersEttings.tofixThis : 1) checktheDefaultPyThonVersionUsingPyThon-VersionorPyThon3- version.2) usvirtual-ErondmentsBythePython.9-Mvenvmyenv, 활성화, 및 파괴

PythonArraysSupportVariousOperations : 1) SlicingExtractsSubsets, 2) 추가/확장 어드먼트, 3) 삽입 값 삽입 ATSpecificPositions, 4) retingdeletesElements, 5) 분류/ReversingChangesOrder 및 6) ListsompectionScreateNewListSbasedOnsistin

NumpyArraysareSentialplosplicationSefficationSefficientNumericalcomputationsanddatamanipulation. Theyarcrucialindatascience, MachineLearning, Physics, Engineering 및 Financeduetotheiribility에 대한 handlarge-scaledataefficivally. forexample, Infinancialanyaly

UseanArray.ArrayOveralistInpyThonWhendealingwithhomogeneousData, Performance-CriticalCode, OrinterFacingwithCcode.1) HomogeneousData : ArraysSaveMemorywithtypepletement.2) Performance-CriticalCode : arraysofferbetterporcomanceFornumericalOperations.3) Interf

아니요, NOTALLLISTOPERATIONARESUPPORTEDBYARRARES, andVICEVERSA.1) ArraySDONOTSUPPORTDYNAMICOPERATIONSLIKEPENDORINSERTWITHUTRESIGING, WHITHIMPACTSPERFORMANCE.2) ListSDONOTEECONSTANTTIMECOMPLEXITEFORDITITICCESSLIKEARRAYSDO.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경
