PyQtでの画像表示
PyQtを使って画像をウィンドウ上に表示させる方法があります。以下にその一例を示します。
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QFileDialog
import sys
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setGeometry(300, 300, 500, 500)
self.createMenubar()
def createMenubar(self):
self.menubar = self.menuBar()
self.filemenu = self.menubar.addMenu('File')
self.openAction()
def openAction(self):
self.open_act = QAction('開く')
self.open_act.setShortcut('Ctrl+O')
self.open_act.triggered.connect(self.openFile)
self.filemenu.addAction(self.open_act)
def openFile(self):
self.filepath = QFileDialog.getOpenFileName(self, 'open file')[0]
このコードは、メニューバーからファイルを選択し、画像をウィンドウ上に表示させる方法を示しています。
PyQtでの画像処理
PyQtを使って画像を等高線のように表示する方法もあります。以下にその一例を示します。
from PIL import Image, ImageOps, ImageFilter
import numpy as np
import matplotlib.pyplot as plt
img = Image.open('300.png')
img = ImageOps.grayscale(img)
img = img.filter(ImageFilter.GaussianBlur(3))
data = np.asarray(img)
plt.contour(data)
plt.show()
このコードは、画像をグレースケール化し、ぼかしを適用した後、その画像を等高線として表示する方法を示しています。
以上が、PyQtを使った画像表示と画像処理の基本的な方法です。これらの方法を組み合わせることで、さまざまな画像処理アプリケーションを作成することが可能です。.