Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận
- Trong Python, một hình ảnh chỉ là một mảng hai chiều. Vì vậy, người ta có thể thực hiện một vài thao tác ma trận bằng cách sử dụng các mô -đun Python khác nhau để có được một số hiệu ứng rất thú vị. Để chuyển đổi hình ảnh bình thường thành bản phác thảo, chúng tôi sẽ thay đổi các giá trị RGB ban đầu của nó và gán các giá trị RGB của nó tương tự như màu xám, theo cách này, một bản phác thảo của hình ảnh đầu vào sẽ được tạo. & NBSP;
- Tiếp cận 1:
- Nhập tất cả các mô -đun cần thiết (Numpy, ImageIO, Scipy.ndimage, OpenCV)
- Lấy đầu vào hình ảnh
Python3
Kiểm tra giá trị RGB của hình ảnh và chuyển đổi thành các giá trị RGB
Hiển thị đầu ra hình ảnh cuối cùng bằng CV2.ImWrite ()
import numpy as np
import imageio
import scipy.ndimage
import cv2
img ____10 import1
import2 import3
import4import5 import6import7import8import9numpy as np0numpy as np1numpy as np2223numpy as np4
import2 numpy as np6
import4numpy as np8import0 import0import1import2import3import4import2import6import7
import4import9import2imageio1import0 import2
import4imageio5import01010 import2imageio1____10 import2
import4import5 import4import55____56
import7import0 import9
scipy.ndimage0import0 scipy.ndimage2
scipy.ndimage3import0 import2import6scipy.ndimage7
import7import8import9
‘
import4import0 import6
--> pip install cv2Tiếp cận 2:
Nhập CV2:This function will load the image i.e in the specified folder.
Sau đó, chúng tôi sẽ nhập CV2 bên trong mã của chúng tôi, sau đó, chúng tôi sẽ sử dụng một số chức năng sau: & NBSP;This function takes color as an argument and then changes the source image color into that color.
1. IMREAD ()- Hàm này sẽ tải hình ảnh i.e trong thư mục được chỉ định. & NBSP; This function will help the image to keep the properties as same by providing the masking to it.
2. CVTColor ()- Hàm này lấy màu làm đối số và sau đó thay đổi màu hình ảnh nguồn thành màu đó.This function is used to modify the image by sharpening the edges of the image, smoothen the image, and will minimize the
3. bitwise_not ()- Hàm này sẽ giúp hình ảnh giữ các thuộc tính giống nhau bằng cách cung cấp mặt nạ cho nó.
4. GAUSSIANBLUR ()- Hàm này được sử dụng để sửa đổi hình ảnh bằng cách mài các cạnh của hình ảnh, làm mịn hình ảnh và sẽ giảm thiểuThis function is used for the normalization of the image as it doesn’t lose its previous properties.
làm mờ tài sản.imwrite() function.
Python3
import imageio
import scipy.ndimage
import cv2
img ____10 import1
import2 import3
import4import5 import6import7import8import9numpy as np0numpy as np1numpy as np2223numpy as np4
import2 numpy as np6
import7import12import13
import4numpy as np8import0 import0import1import2import3import4import2import6import7
import4import9import2imageio1import0 import2
Output:
import4imageio5import01010 import2imageio1____10 import2
import4import9import2imageio1import0 import2
Output: