Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python library for downsampling a photo

skimage_resized = resize(mask, (mask.shape[0]//2, mask.shape[1]//2), mode='constant')
print(skimage_resized.shape, np.unique(mask_resized))

skimage_rescale = rescale(mask, 1.0/2.0, mode='constant')
print(skimage_rescale.shape, np.unique(mask_resized))

ndimage_resized = ndimage.interpolation.zoom(mask, 0.5)
print(ndimage_resized.shape, np.unique(mask_resized))


cv2_resized = cv2.resize(mask, (mask.shape[0]//2, mask.shape[1]//2),
                        interpolation=cv2.INTER_NEAREST)
print(cv2_resized.shape, np.unique(mask_resized))

mask_pil = Image.fromarray(mask, mode=None)
pil_resized = mask_pil.thumbnail((mask.shape[0]//2, mask.shape[1]//2), Image.NEAREST)
print(skimage_resized.shape, np.unique(pil_resized))
Comment

python downsample image

import numpy as np
from scipy import ndimage

def block_mean(ar, fact):
    assert isinstance(fact, int), type(fact)
    sx, sy = ar.shape
    X, Y = np.ogrid[0:sx, 0:sy]
    regions = sy/fact * (X/fact) + Y/fact
    res = ndimage.mean(ar, labels=regions, index=np.arange(regions.max() + 1))
    res.shape = (sx/fact, sy/fact)
    return res
  
 # Example:
ar = np.random.rand(20000).reshape((100, 200))
block_mean(ar, 5).shape  # (20, 40)
Comment

PREVIOUS NEXT
Code Example
Python :: while loop in python 
Python :: continue and break in python 
Python :: dict in dict in python 
Python :: fizz buzz 
Python :: numpy evenly spaced numbers 
Python :: python ternary elif 
Python :: how to code a trading bot in python 
Python :: django model query join 
Python :: pip change python version 
Python :: brute force string matching algorithm in python 
Python :: what is the difference between accuracy and loss 
Python :: pytorch dill model save 
Python :: print output 
Python :: print format round python 
Python :: pandas if value present in df index 
Python :: progress bar in python 
Python :: phyton 2.7 convert timedelta to string 
Python :: open image in PILLOW 
Python :: Python __mul__ magic method 
Python :: python how to convert a list of floats to a list of strings 
Python :: relative text size put text cv2 
Python :: tensorflow neural network 
Python :: how to add elements to a dictionary 
Python :: join two querysets django 
Python :: faker, generates fake data for you 
Python :: how to set global variable in python function 
Python :: why wont my python input accept string inputs 
Python :: args and kwargs 
Python :: heapsort python 
Python :: promises in python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =