각종resize

10145 단어 기계 학습

opencv

  • python
  • resize(src, dsize, dst, fx, fy, interpolation)
    

    그 중에서 dsize와 fx&fy 둘 중 하나를 선택하면 됩니다. dsize는 (width,height) 모드이고 interpolation은 삽입 방식이며 기본값은INTER 입니다.LINEAR
    코드
    보간법
    INTER_NEAREST
    최근 인접 보간(빠르지만 앤티앨리어싱)
    INTER_LINEAR
    이중 보간(기본값, 빠른 속도, 괜찮은 효과)
    INTER_AREA
    픽셀 영역 관계를 사용하여 재샘플링(이미지 축소 권장)
    INTER_CUBIC
    4x4 픽셀 인접 영역의 더블 세 번 삽입값 (속도가 느리고 효과가 좋다)
    INTER_LANCZOS4
    8x8 픽셀 인접 영역에 대한 Lanczos 보간
    img = cv2.imread('test.jpg')
    height, width = img.shape[:2] #shape (height, width, channel)  
    img_resize = cv2.resize(img, (width / 2, height / 2), interpolation=cv2.INTER_NEAREST) #dsize (width, height)  
    img_resize = cv2.resize(img, (0, 0), None, fx=0.5, fy=0.5)
    
  • c
  • #include 
    #include 
    cv::Mat img = cv::imread("test.jpg", 1);
    cv::Mat img_resize;
    cv::resize(img, img_resize, cv::Size(200, 100), 0, 0, cv::INTER_LINEAR);
    

    PIL


    축소 방식은NEAREST,BOX,BILINEAR,HAMMING,BICUBIC,LANCZOS,기본값은NEAREST,size모드는(width,height)
    import PIL.Image as Image
    img = Image.open('test.jpg')
    height, width = img.height, img.width
    img_resize = img.resize((width / 2, height / 2), Image.BILINEAR)
    

    Keras


    size의 모드는 (height,width)이고 PIL의resize 방법을 사용합니다
    image_size = (image_height, image_width)
    train_datagen = ImageDataGenerator(rescale=1.0/255)
    train_generator = train_datagen.flow_from_directory(
            'datasets/mytrain',  # this is the target directory
            target_size=image_size,  # all images will be resized to 224x224
            batch_size=16,
            class_mode='binary')
    

    Tensorflow

    tf.image.resize_images(
        images,
        size,
        method=ResizeMethod.BILINEAR,
        align_corners=False
    )
    

    size의 모드는 (height,width)입니다. 삽입 방식은 다음과 같습니다. Resize Method.BILINEAR: 이중 보간(기본값) ResizeMethod.NEAREST_NEIGHBOR: 가장 가까운 이웃 삽입값.ResizeMethod.BICUBIC: 더블 세 번 삽입값.ResizeMethod.AREA: 영역 보간.
    img_raw = cv2.imread('test.jpg')
    h, w, _ = img_in.shape
    tf_img_in = tf.placeholder(dtype=tf.float32, shape=(None, None, 3))
    scale = 0.5
    tf_img_op1 = tf.image.resize_images(tf_img_in, [h * scale, w * scale], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) #    tensor
    

    좋은 웹페이지 즐겨찾기