머신러닝/Computer Vision

딥러닝 모델 input이 3channel (RGB)기반 모델인데, Grayscale로 inference/validate을 진행하고 싶을 때는 기존 RGB Load방식에서 아래와 같이 1 channel로 로드하고 동일한 layer를 3겹 쌓아서 넘겨주면 됨. 맨날 함수를 까먹어서 기록용. im = cv2.imread(f, cv2.IMREAD_GRAYSCALE) if len(im.shape)
기존에 적은 게시물의 연장이라 보면 될 것 같다. [PIL] Crop / Clip image by Polygon points. / PIL로 이미지 자르기 # FOR PNG shape import numpy from PIL import Image, ImageDraw # read image as RGB and add alpha (transparency) im = Image.open("crop.jpg").convert("RGBA") # convert to numpy (for convenience) imArray = numpy.asarray(im) # create mask polygon = [(444,203),( yjs-program.tistory.com 일전에 작성한대로 crop을 한 후, 해당 글자 이미지를..
class RawDataset(Dataset): def __init__(self, root): self.rgb = True self.image_path_list = [] for dirpath, dirnames, filenames in os.walk(root, followlinks=True): for name in filenames: _, ext = os.path.splitext(name) ext = ext.lower() if ext == ".jpg" or ext == ".jpeg" or ext == ".png": self.image_path_list.append(os.path.join(dirpath, name)) self.image_path_list = natsorted(self.image_path_li..
def strike(draw, img, font, text): # Get the image, and calculate the average of font thickness. twidth, theight = img.size lx, ly = twidth, theight/2 thickness = 2 if twidth >200 or theight > 200 else 1 draw.line((0, ly, lx, ly), fill="black", width=thickness) # [0, height/2] ~ [width, height/2] # "*"처럼 위로 올려붙는 특수 문자의 경우, font의 getmask함수로 영역을 잡아줘야 함. def special_strike(draw, img, font, text): t..
https://stackoverflow.com/questions/43060479/how-to-get-the-font-pixel-height-using-pils-imagefont-class How to get the font pixel height using PIL's ImageFont class? I am using PIL' ImageFont module to load fonts to generate text images. I want the text to tightly bound to the edge, however, when using the ImageFont to get the font height, It seems that it incl... stackoverflow.com Font Loading..
64의 배수로 input size를 조정해주면 된다. 내가 많이 쓰는 input size는 640 .... , 1024, 1600... 등이 있다. https://github.com/CompVis/stable-diffusion/issues/301
matplotlib plt.subplots warning 삭제 for문과 matplotlib를 사용해서 이미지를 그릴 때, 다음과 같은 warning이 나오는 경우가 있다. RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). 이럴때는 내가 열어준 fig를 close()해주지 않아서 ..
https://matplotlib.org/stable/gallery/shapes_and_collections/hatch_style_reference.html Hatch style reference — Matplotlib 3.7.1 documentation Note Click here to download the full example code Hatch style reference Hatches can be added to most polygons in Matplotlib, including bar, fill_between, contourf, and children of Polygon. They are currently supported in the PS, PDF, SVG, OSX, and Agg bac..
import torch from tqdm.notebook import tqdm import glob from PIL import Image from torchvision.transforms import ToTensor target_path = "./images/*" img_lst = glob.glob(target_path) totensor = ToTensor() img_val_lst = [] for img in tqdm(img_lst): img_RGB = Image.open(img).convert("RGB") img_val = totensor(img_RGB) img_val_lst.append(img_val) mean = torch.zeros(3) std = torch.zeros(3) print('==> ..
https://pypi.org/project/polygon-pascalvoc-writer/ polygon-pascalvoc-writer For generating Pascal VOC XML image annotation files pypi.org 응용 코드 import glob from tqdm import tqdm import os import json import xmltodict import cv2 import codecs import numpy as np from shutil import copyfile from polygon_pascalvoc_writer import VocWriter CLASS_label = ['CLASS_A', 'CLASS_B', ...] #https://blog.actors..
https://github.com/fcakyon/labelme2coco GitHub - fcakyon/labelme2coco: A lightweight package for converting your labelme annotations into COCO object detection format. A lightweight package for converting your labelme annotations into COCO object detection format. - GitHub - fcakyon/labelme2coco: A lightweight package for converting your labelme annotations into ... github.com json_load 함수나 save..
아래 코드는 input 이미지가 jpg형식일 때 적용 가능한 코드 from PIL import Image, ImageDraw, ImageFont # Open the image file image = Image.open('./input_image.jpg') # Create a drawing context for the image draw = ImageDraw.Draw(image, "RGBA") # Define the polygon points polygon_points = [(50, 50), (200, 50), (200, 200), (50, 200)] #polygon_points = [50, 50, 200, 50, 200, 200, 50, 200] # Define the fill color and tran..
# x, y, w, h ROI img = cv2.imread('test.jpg') cropped_img = img[y: y + h, x: x + w] 참고자료 : https://eehoeskrap.tistory.com/419
Github : https://github.com/yellowjs0304/PascalVOC2Yolo 코드는 데이터 디렉토리 안에 배치 ┌── Data Directory ├── images : Image set Directory ├── train : XML set Directory(for Train) ├── val : XML set Directory(for Validation) ├── test : XML set Directory(for Test) ├── images_filelist.txt : List of Image Pathes ├── train_filelist.txt : List of Train XML pathes ├── val_filelist.txt : List of Validation XML path..
1. ColorThief PIL, python을 기반으로 하고 있는 모듈로 특정 이미지 내 color palette를 추출하거나 대표 컬러를 추출할 수 있음. 설치 방법은 아래 PIP 명령어 참고 $pip install colorthief 사용법은 아래와 같다 ColorThief 설치 후, 이미지를 colorthief 객체에 넣어준다. get_color 함수와 get_palette함수로 원하는 컬러를 얻어온다. 각 함수에 대한 자세한 설명은 다음 링크를 참고하자. GitHub - fengsp/color-thief-py: Grabs the dominant color or a representative color palette from an image. Uses Python and Pillow Grabs t..
Js.Y
'머신러닝/Computer Vision' 카테고리의 글 목록