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==0.0.4


pip install jenti

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.4.tar.gz (5.9 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.4-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jenti-0.0.4.tar.gz
Algorithm Hash digest
SHA256 32187d6461caacff6876f4c62221555fa9e4bc26ece041922bef40c47ed9dfb2
MD5 09c263a1bb66e8ee1da5b8de0ec3806f
BLAKE2b-256 4029bcfb77576860ec48f417b142dfa930d5a6e7dbb3e2f63b33b40499495dfb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenti-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 16a1f1688f102512101434419184acbd20515ca07e51a5a99094af7f243e8ce1
MD5 92e75f0ee29dadeaecf2b457ecc39022
BLAKE2b-256 7bc92335b8d3d2ebc0318ee1e57e87fdca51d05dee5b71518544c1f7af72fb18

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