Skip to content
Snippets Groups Projects
Commit 559f0b9a authored by Hyunseok_Sang's avatar Hyunseok_Sang
Browse files

이미지 처리를 위한 util 클래스 추가

parent 863200a5
Branches
No related tags found
No related merge requests found
from utils.image.image_converter import ImageConverter
class ImageChopper:
@staticmethod
def chop_left(image, w):
img = ImageConverter().convert_to_np_image(image)
chopped_img = img[:, w:]
return chopped_img
@staticmethod
def chop_right(image, w):
img = ImageConverter().convert_to_np_image(image)
chopped_img = img[:, :-w]
return chopped_img
@staticmethod
def chop_top(image, h):
img = ImageConverter().convert_to_np_image(image)
chopped_img = img[h:, :]
return chopped_img
@staticmethod
def chop_bottom(image, h):
img = ImageConverter().convert_to_np_image(image)
chopped_img = img[:-h, :]
return chopped_img
@staticmethod
def chop_border(image, w):
img = ImageConverter().convert_to_np_image(image)
chopped_img = img[w:-w, w:-w]
return chopped_img
\ No newline at end of file
import numpy as np
class ImageCompister:
def composite(self, outer_np_image, inner_np_image, x_offset = 0, y_offset = 0):
'''
if isinstance(outer_image, CompositedImage):
outer_image_copy = np.copy(outer_image.outer_image)
inner_image = outer_image.inner_image
x_offset = outer_image.x_offset
y_offset = outer_image.y_offset
elif isinstance(outer_image, np.ndarray):
outer_image_copy = np.copy(outer_image)
'''
outer_np_image_copy = np.copy(outer_np_image)
outer_np_image_copy[y_offset:y_offset + inner_np_image.shape[0], x_offset:x_offset + inner_np_image.shape[1]] = inner_np_image
return outer_np_image_copy
\ No newline at end of file
import cv2
import numpy as np
class ImageConverter:
def convert_to_np_image(self, image):
if isinstance(image, bytes):
npimg = np.fromstring(image, np.uint8)
img = cv2.imdecode(npimg, cv2.IMREAD_COLOR)
elif isinstance(image, np.ndarray):
img = image
elif isinstance(image, str):
img = cv2.imread(image)
return img
\ No newline at end of file
import cv2
class ImageResizer:
def resize(self, np_image, width, height):
np_image = cv2.resize(np_image, (width, height))
return np_image
def enlarge_according_to_mask(np_image, mask, ratio = 50):
object_long_side_length = mask.get_long_side_length()
np_image = cv2.cvtColor(np_image, cv2.COLOR_RGB2RGBA)
#인물의 객체의 긴 길이가 50%, 1024*1024에서 약 50%(550픽셀)을 차지하도록 설정
new_width = int(np_image.shape[1]*ratio*10/object_long_side_length)
new_height = int(np_image.shape[0]*ratio*10/object_long_side_length)
np_image = cv2.resize(np_image, (new_width, new_height))
return np_image
\ No newline at end of file
import cv2
class ImageWriter:
def save_np_image(self, np_image, dir_name = '.' , file_name = "no_named.png"):
file_dir = dir_name + '/' + file_name
cv2.imwrite(file_dir, np_image)
return file_dir
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment