Bilişim dünyasına kaliteli, özgün ve Türkçe içerikler kazandırmayı hedefleyen bir platform..

friends friends friends

Python'da Resim Göstermenin 5 Yolu

Python'da Resim Göstermenin 5 Yolu

  1. OpenCV
  2. Matplotlib
  3. Pillow
  4. Scikit-Image
  5. Tensorflow

1- OpenCV

import sys # to access the system
import cv2
img = cv2.imread("sheep.png", cv2.IMREAD_ANYCOLOR)
 
while True:
    cv2.imshow("Sheep", img)
    cv2.waitKey(0)
    sys.exit() # to exit from all the processes
 
cv2.destroyAllWindows() # destroy all windows
Displaying-image-through-OpenCV

2- Matplotlib

from matplotlib import pyplot as plt
from matplotlib import image as mpimg
 
plt.title("Sheep Image")
plt.xlabel("X pixel scaling")
plt.ylabel("Y pixels scaling")
 
image = mpimg.imread("sheep.png")
plt.imshow(image)
plt.show()
Displaying-image-through-Matplotlib

3- Pillow

from PIL import Image
img = Image.open("sheep.png")
img.show()

Reim ile ilgili width, height değerlerine ulaşmak istersek ya da RGB değerlerini bir matrix içine aktarmak istersek aşağıdaki kodu kullanabiliriz:

from PIL import Image
with Image.open("image.jpg") as im:
    w, h =im.size
    matrix = im.load()
    
    
print(matrix[1,2])#(42, 61, 94)

Resim ile ilgili diğer detayları göstermek için aşağıdaki kodları kullanabiliriz:

from PIL import Image

img = Image.open("resim.jpg")

img.show()

# The file format of the image file.
print(img.format) # Output: JPEG

# The pixel format used by the image file.Typical values can be "1", "L", "RGB", or "CMYK."
print(img.mode) # Output: RGB

# Prints image size, in pixels.The size is given as a tuple(width, height)
  
print(img.size) # Output: (1920, 1280)

4- Scikit-Image

from skimage import io
 
img = io.imread("sheep.png")
io.imshow(img)
Displaying-image-through-Skimage

5- Tensorflow

from warnings import filterwarnings
import tensorflow as tf
from tensorflow import io
from tensorflow import image
from matplotlib import pyplot as plt
 
filterwarnings("ignore") 
tf_img = io.read_file("sheep.png")
tf_img = image.decode_png(tf_img, channels=3)
print(tf_img.dtype)
plt.imshow(tf_img)
# plt.show()
Displaying-image-through-Tensorflow-and-matplotlib
image python image
0 Beğeni
Python
Önceki Yazı

Python Image Full path is needed

27 Ağu. 2022 tarihinde yayınlandı.
Sonraki Yazı

Canny Edge Detection

27 Ağu. 2022 tarihinde yayınlandı.
arrow