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 :: prefix in python 
Python :: how to find the length of a list in python 
Python :: Django forms I cannot save picture file 
Python :: how do i re-restablish the third reich 
Python :: nums: List[int] in python function 
Python :: how to delete lists after using them in python 
Python :: django multi column index 
Python :: draw a marker in basemap python 
Python :: python bill 
Python :: how to write flow of execution in python 
Python :: draw networkx graph using plt.pause 
Python :: python import class as alias 
Python :: how to write a program that interacts with the terminal 
Python :: hidden semi markov model python from scratch 
Python :: load pandas dataframe with one row per line and 1 column no delimiter 
Python :: numpy index array all except 
Python :: how to check if an array is empty in python 
Python :: Improve the Request Handle Errors 
Python :: Python Importing module from a package 
Python :: REST APIs with Flask and Python free download 
Python :: Ignoring NaNs with str.contains 
Python :: pyspark percentage missing values 
Python :: how to save a from with createvue django 
Python :: poisson random data 
Python :: np logical and 
Python :: sample clustering of articles using kmeans and trncatedSVD 
Python :: Python Code for Checking if a number is an Odd number 
Python :: connection to python debugger failed: socket closed 
Python :: Tree : Top View 
Python :: Dataframe with defined shape filled with 0 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =