當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.NEAREST屬性代碼示例

本文整理匯總了Python中PIL.Image.NEAREST屬性的典型用法代碼示例。如果您正苦於以下問題:Python Image.NEAREST屬性的具體用法?Python Image.NEAREST怎麽用?Python Image.NEAREST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在PIL.Image的用法示例。


在下文中一共展示了Image.NEAREST屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def __call__(self, sample):
        img = sample['image']
        mask = sample['label']
        assert img.size == mask.size
        w, h = img.size

        # if one side is 512
        if (w >= h and w == self.size[1]) or (h >= w and h == self.size[0]):
            return {'image': img,
                    'label': mask}
        # if both sides is not equal to 512, resize to 512 * 512
        oh, ow = self.size
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)

        return {'image': img,
                'label': mask} 
開發者ID:songdejia,項目名稱:DeepLab_v3_plus,代碼行數:19,代碼來源:transform.py

示例2: __call__

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def __call__(self, sample):
        img = sample['image']
        mask = sample['label']
        w, h = img.size
        if w > h:
            oh = self.crop_size
            ow = int(1.0 * w * oh / h)
        else:
            ow = self.crop_size
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - self.crop_size) / 2.))
        y1 = int(round((h - self.crop_size) / 2.))
        img = img.crop((x1, y1, x1 + self.crop_size, y1 + self.crop_size))
        mask = mask.crop((x1, y1, x1 + self.crop_size, y1 + self.crop_size))

        return {'image': img,
                'label': mask} 
開發者ID:clovaai,項目名稱:overhaul-distillation,代碼行數:23,代碼來源:custom_transforms.py

示例3: preprocess_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def preprocess_image(image_path, inp_dims):
    ppm_image = Image.open(image_path)
    # resize image
    new_h = 224
    new_w = 224
    size = (new_w, new_h)
    # resize image
    img = ppm_image.resize(size, Image.NEAREST)
    # convert to numpy array
    img = np.array(img)
    # hwc2chw
    img = img.transpose(2, 0, 1)
    # convert image to 1D array
    img = img.ravel()
    # convert image to float
    img = img.astype(np.float32)
    # normalize image data
    img = normalize_data(img, inp_dims)
    return img 
開發者ID:aimuch,項目名稱:iAI,代碼行數:21,代碼來源:sample_onnx.py

示例4: update_preview

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def update_preview(self, psize):
        # Safety check: Ignore calls during construction/destruction.
        if not self.init_done: return
        # Copy latest user settings to the lens object.
        self.lens.fov_deg = self.f.get()
        self.lens.radius_px = self.r.get()
        self.lens.center_px[0] = self.x.get()
        self.lens.center_px[1] = self.y.get()
        # Re-scale the image to match the canvas size.
        # Note: Make a copy first, because thumbnail() operates in-place.
        self.img_sc = self.img.copy()
        self.img_sc.thumbnail(psize, Image.NEAREST)
        self.img_tk = ImageTk.PhotoImage(self.img_sc)
        # Re-scale the x/y/r parameters to match the preview scale.
        pre_scale = float(psize[0]) / float(self.img.size[0])
        x = self.x.get() * pre_scale
        y = self.y.get() * pre_scale
        r = self.r.get() * pre_scale
        # Clear and redraw the canvas.
        self.preview.delete('all')
        self.preview.create_image(0, 0, anchor=tk.NW, image=self.img_tk)
        self.preview.create_oval(x-r, y-r, x+r, y+r,
                                 outline='#C00000', width=3)

    # Make a combined label/textbox/slider for a given variable: 
開發者ID:ooterness,項目名稱:DualFisheye,代碼行數:27,代碼來源:fisheye.py

示例5: __call__

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def __call__(self, img, mask):
        if self.padding > 0:
            img = ImageOps.expand(img, border=self.padding, fill=0)
            mask = ImageOps.expand(mask, border=self.padding, fill=0)

        assert img.size == mask.size
        w, h = img.size
        th, tw = self.size
        if w == tw and h == th:
            return img, mask
        if w < tw or h < th:
            return img.resize((tw, th), Image.BILINEAR), mask.resize((tw, th), Image.NEAREST)

        x1 = random.randint(0, w - tw)
        y1 = random.randint(0, h - th)
        return img.crop((x1, y1, x1 + tw, y1 + th)), mask.crop((x1, y1, x1 + tw, y1 + th)) 
開發者ID:zhechen,項目名稱:PLARD,代碼行數:18,代碼來源:augmentations.py

示例6: __call__

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def __call__(self, rgb_img, label_img=None):

        label1 = label_img
        label2 = label_img
        if self.scale1 != 1:
            w, h = label_img.size
            label1 = label1.resize((w//self.scale1, h//self.scale1), Image.NEAREST)

        if self.scale2 != 1:
            w, h = label_img.size
            label2 = label2.resize((w//self.scale2, h//self.scale2), Image.NEAREST)

        rgb_img = F.to_tensor(rgb_img) # convert to tensor (values between 0 and 1)
        rgb_img = F.normalize(rgb_img, self.mean, self.std) # normalize the tensor
        label1 = torch.LongTensor(np.array(label1).astype(np.int64))
        label2 = torch.LongTensor(np.array(label2).astype(np.int64))


        return rgb_img, label1, label2 
開發者ID:clovaai,項目名稱:ext_portrait_segmentation,代碼行數:21,代碼來源:PILTransform.py

示例7: get_transform2

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def get_transform2(dataset_name, net_transform, downscale):
    "Returns image and label transform to downscale, crop and prepare for net."
    orig_size = get_orig_size(dataset_name)
    transform = []
    target_transform = []
    if downscale is not None:
        transform.append(transforms.Resize(orig_size // downscale))
        target_transform.append(
                transforms.Resize(orig_size // downscale,
                    interpolation=Image.NEAREST))
    transform.extend([transforms.Resize(orig_size), net_transform]) 
    target_transform.extend([transforms.Resize(orig_size, interpolation=Image.NEAREST),
        to_tensor_raw]) 
    transform = transforms.Compose(transform)
    target_transform = transforms.Compose(target_transform)
    return transform, target_transform 
開發者ID:jhoffman,項目名稱:cycada_release,代碼行數:18,代碼來源:data_loader.py

示例8: __call__

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def __call__(self, input, target):
        # do something to both images and labels
        if self.reshape_size is not None:
            input = input.resize(self.reshape_size,Image.BILINEAR)
            target = target.resize(self.reshape_size,Image.NEAREST)
 
        if self.augment :
            input, target = RandomCrop(self.crop_size)(input,target) # RandomCrop for  image and label in the same area
            input, target = self.flip(input,target)               # RandomFlip for both croped image and label
            input, target = self.rotate(input,target)
        else:
            input, target =  CenterCrop(self.crop_size)(input, target) # CenterCrop for the validation data
            
        input = ToTensor()(input)  
        Normalize([.485, .456, .406], [.229, .224, .225])(input) #normalize with the params of imagenet
          
        target = torch.from_numpy(np.array(target)).long().unsqueeze(0)

        return input, target 
開發者ID:mapleneverfade,項目名稱:pytorch-semantic-segmentation,代碼行數:21,代碼來源:transform.py

示例9: _val_sync_transform

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def _val_sync_transform(self, img, mask):
        outsize = self.crop_size
        short_size = outsize
        w, h = img.size
        if w > h:
            oh = short_size
            ow = int(1.0 * w * oh / h)
        else:
            ow = short_size
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - outsize) / 2.))
        y1 = int(round((h - outsize) / 2.))
        img = img.crop((x1, y1, x1 + outsize, y1 + outsize))
        mask = mask.crop((x1, y1, x1 + outsize, y1 + outsize))
        # final transform
        img, mask = self._img_transform(img), self._mask_transform(mask)
        return img, mask 
開發者ID:AceCoooool,項目名稱:LEDNet,代碼行數:23,代碼來源:base_seg.py

示例10: _val_sync_transform

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def _val_sync_transform(self, img, mask):
        outsize = self.crop_size
        short_size = min(outsize)
        w, h = img.size
        if w > h:
            oh = short_size
            ow = int(1.0 * w * oh / h)
        else:
            ow = short_size
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - outsize[1]) / 2.))
        y1 = int(round((h - outsize[0]) / 2.))
        img = img.crop((x1, y1, x1 + outsize[1], y1 + outsize[0]))
        mask = mask.crop((x1, y1, x1 + outsize[1], y1 + outsize[0]))

        # final transform
        img, mask = self._img_transform(img), self._mask_transform(mask)
        return img, mask 
開發者ID:LikeLy-Journey,項目名稱:SegmenTron,代碼行數:24,代碼來源:seg_data_base.py

示例11: pixelize_screenshot

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def pixelize_screenshot(screenshot, screenshot_pixelized, target_width=390, pixelsize=3):
    """
    Thumbnail a screenshot to `target_width` and pixelize it.

    :param screenshot: Screenshot to be thumbnailed in pixelized
    :param screenshot_pixelized: File to which the result should be written
    :param target_width: Width of the final thumbnail
    :param pixelsize: Size of the final pixels
    :return: None
    """
    if target_width % pixelsize != 0:
        raise ValueError("pixelsize must divide target_width")

    img = Image.open(screenshot)
    width, height = img.size
    if height > width:
        img = img.crop((0, 0, width, width))
        height = width
    undersampling_width = target_width // pixelsize
    ratio = width / height
    new_height = int(undersampling_width / ratio)
    img = img.resize((undersampling_width, new_height), Image.BICUBIC)
    img = img.resize((target_width, new_height * pixelsize), Image.NEAREST)
    img.save(screenshot_pixelized, format='png') 
開發者ID:PrivacyScore,項目名稱:PrivacyScore,代碼行數:26,代碼來源:openwpm.py

示例12: _val_sync_transform

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def _val_sync_transform(self, img, mask):
        outsize = self.crop_size
        short_size = outsize
        w, h = img.size
        if w > h:
            oh = short_size
            ow = int(1.0 * w * oh / h)
        else:
            ow = short_size
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - outsize) / 2.))
        y1 = int(round((h - outsize) / 2.))
        img = img.crop((x1, y1, x1+outsize, y1+outsize))
        mask = mask.crop((x1, y1, x1+outsize, y1+outsize))
        # final transform
        img, mask = self._img_transform(img), self._mask_transform(mask)
        return img, mask 
開發者ID:dmlc,項目名稱:gluon-cv,代碼行數:23,代碼來源:segbase.py

示例13: _val_sync_transform

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def _val_sync_transform(self, img, mask):
        outsize = self.crop_size
        short_size = outsize
        w, h = img.size
        if w > h:
            oh = short_size
            ow = int(1.0 * w * oh / h)
        else:
            ow = short_size
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - outsize) / 2.))
        y1 = int(round((h - outsize) / 2.))
        img = img.crop((x1, y1, x1+outsize, y1+outsize))
        mask = mask.crop((x1, y1, x1+outsize, y1+outsize))
        # final transform
        return img, self._mask_transform(mask) 
開發者ID:zhanghang1989,項目名稱:PyTorch-Encoding,代碼行數:22,代碼來源:base.py

示例14: _val_sync_transform

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def _val_sync_transform(self, img, mask):
        """
        synchronized transformation
        """
        outsize = 720
        short = outsize
        w, h = img.size
        if w > h:
            oh = short
            ow = int(1.0 * w * oh / h)
        else:
            ow = short
            oh = int(1.0 * h * ow / w)
        img = img.resize((ow, oh), Image.BILINEAR)
        mask = mask.resize((ow, oh), Image.NEAREST)
        # center crop
        w, h = img.size
        x1 = int(round((w - outsize) / 2.))
        y1 = int(round((h - outsize) / 2.))
        img = img.crop((x1, y1, x1+outsize, y1+outsize))
        mask = mask.crop((x1, y1, x1+outsize, y1+outsize))

        return img, mask 
開發者ID:zhanghang1989,項目名稱:PyTorch-Encoding,代碼行數:25,代碼來源:cityscapescoarse.py

示例15: write

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import NEAREST [as 別名]
def write(self, s):
        global lcd
        image = Image.frombuffer('L', P_SIZE, s, "raw", 'L', 0, 1)
        image = image.crop((self.x, 0, self.x+1, P_HEIGHT))
        self.image_scan.paste(image,(self.x, 0))
        if self.x < P_WIDTH-1:
            self.x += 1
        image = ImageOps.invert(self.image_scan)
        image.thumbnail(S_SIZE, Image.NEAREST)
        image = image.convert('1')
        lcd.write(image.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:13,代碼來源:video_test2.py


注:本文中的PIL.Image.NEAREST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。