Python으로 이미지를 변경하는 방법
PyCharm을 열고 PycharmProjects 디렉토리에 imagePython 프로젝트를 만듭니다.
일반적으로 PyCharm은 자동으로 생성합니다.
사진으로 작업하고 싶어서 Mac용pillow을 설치합니다.
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
디렉터리 이미지를 생성하고 수정하려는 사진을 다운로드할 때Pixabay . 작은 이미지를 선택하는 것이 좋습니다. 그러면 변환하는 데 시간이 덜 걸립니다.
이제 main.py 파일을 변경합니다.
from PIL import Image
tulips = Image.open("./images/tulips.jpeg")
tulips.show()
이 코드를 실행하면 다음과 같은 결과가 나타납니다.

이미지가 이름과 형식을 변경하는 것을 볼 수 있습니다.
이제 이미지를 회전할 수 있습니다.
rotateImage = tulips.rotate(180)
rotateImage.show()

크기를 조정할 수도 있습니다.
little = tulips.resize((128, 128))
little.show()

이제 색상을 흰색과 검정색으로 변경합니다.
# all is black and white
im = tulips.convert("L")
im.show()

다음과 같이 이미지의 색상을 변경할 수도 있습니다.
r, g, b = tulips.split()
r = r.point(lambda i: i * 2)
g = g.point(lambda i: i / 2)
b = b.point(lambda i: i + 50)
img = Image.merge("RGB", (r, g, b))
img.getextrema()
img.show()

문서에서 찾을 수 있는 것보다 흐림 또는 윤곽과 같은 일부 필터를 사용할 수도 있습니다.
from PIL import ImageFilter
im1 = tulips.filter(ImageFilter.BLUR)
im1.show()
im2 = tulips.filter(ImageFilter.CONTOUR)
im2.show()


내 이미지의 대비도 조절할 수 있습니다.
from PIL import ImageEnhance
# contrast of 50%
contrastedImg = ImageEnhance.Contrast(tulips)
contrastedImg.enhance(1.5).show()

이들은 베개 가능성의 일부 예일 뿐이므로 주저하지 말고 테스트하고 프로젝트에 사용하십시오.
Reference
이 문제에 관하여(Python으로 이미지를 변경하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/deotyma/how-to-change-an-image-with-python-518d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)