Skip to main content

To create/merge 2D or 3D patches.

Project description

Patch and Merge

  1. Can create patches from both 2D or 3D images
  2. Can merge 2D or 3D patches

As for 3D, the primary focus is 3D CT data. The data should be converted to an array before making 3D patches.

So, the 2D image or 3D volume is needed to convert to an array first.

How to install

pip install jenti

How to check version

import jenti
print(jenti.__version__)

How to use

Sample demonstration on how to use this code is given in test.py and test.ipynb.

How to import

from jenti import patch

Create patches from a 2D image

# Read image
im = Image.open('c.jpg') # color image
im.show()
image = np.array(im) # convert to array

# Create patches
patch_shape = [100, 100]
overlap = [10,10] # overlap between two adjacent patches along both axes
patch = Patch(patch_shape, overlap, patch_name='patch2d', csv_output=True)
patches, info, org_shape = patch.patch2d(image)

# Save patches       
patch.save2d(patches, save_dir='./save2d', ext = '.png')

If the csv_output is set to True, then it will save the locations of each patch in the original image in a csv file.
Patch names will be like: xxxx0000, xxxx0001, xxxx0002, and so on.

Create patches from a 3D volume

# Read volume
data = sio.loadmat('volume.mat')
data = data['data'] # shape: 128 x 128 x 50  x 1

# Create patches
patch_shape = [32, 32, 16, 1] # H x W x D x Ch
overlap = [8, 8, 8, 0]
patch = Patch(patch_shape, overlap, patch_name='patch3d', csv_output=True)
patches, info, org_shape = patch.patch3d(data)

# Save patches
patch.save3d(patches, save_dir='./save3d', ext = '.mat')

Merge 2D patches
Merging can be done in two ways.
Method 1: Read all the patch files first, then merge them together.

# Merge patches
names = os.listdir('./save2d')
patches = []
info = pd.read_csv('patch2d.csv')
info = np.array(info)
org_shape = (3024, 4032, 3)

for name in names:
    p = Image.open(os.path.join('./save2d', name))
    p = np.array(p)
    patches.append(p)
    
merge = Merge(info, org_shape, dtype='uint8')
merged = merge.merge2d(patches)
merged_im = Image.fromarray(merged)
merged_im.show()
merged_im.save('merged2d.png')

Method 2: Provide only the patch directory.

merge = Merge(info, org_shape, dtype='uint8')
merged = merge.merge_from_dir2d('./save2d') 
merged_im = Image.fromarray(merged)
merged_im.show()
merged_im.save('merged2d.png')

Merge 3D patches
Method 1: Read all the patch files first, then merge them together.

# Merge patches
names = os.listdir('./save3d')
patches = []
info = pd.read_csv('patch3d.csv')
info = np.array(info)
org_shape = (128, 128, 50, 1)

for name in names:
    p = sio.loadmat(os.path.join('./save3d', name))
    p = p['p']
    patches.append(p)
    
merge = Merge(info, org_shape, dtype='float32')
merged = merge.merge3d(patches)
sio.savemat('merged3d.mat', {'m': merged}, do_compression=True)

Method 2: Provide only the patch directory.

merge = Merge(info, org_shape, dtype='float32')
merged = merge.merge_from_dir3d('./save3d') 
sio.savemat('merged3d.mat', {'m': merged}, do_compression=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jenti-0.0.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jenti-0.0.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file jenti-0.0.3.tar.gz.

File metadata

  • Download URL: jenti-0.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for jenti-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2a4fdff4f5e267f1deb4cae0046526518b627d27132a9e0df211c00cfb3c3d15
MD5 d35ae0817bf94010c94a10a3dc6d25d8
BLAKE2b-256 29538bb7648cff515f776a608fc391c51cf2a49ec3c87e221b37bb5fa84faddd

See more details on using hashes here.

File details

Details for the file jenti-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jenti-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for jenti-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c73c224cc80aac4bef89d36e5cc34176ee7c190880c3a8ab043178ebb3fc1997
MD5 0d912dba2c58bb59f009668c02520055
BLAKE2b-256 cd7c77f06527286bfa8b07f5163abcfe03b9dcc7c797e72c302f5bc5b8e3df6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page