summaryrefslogtreecommitdiff
path: root/python-patchify.spec
diff options
context:
space:
mode:
Diffstat (limited to 'python-patchify.spec')
-rw-r--r--python-patchify.spec304
1 files changed, 304 insertions, 0 deletions
diff --git a/python-patchify.spec b/python-patchify.spec
new file mode 100644
index 0000000..90671d2
--- /dev/null
+++ b/python-patchify.spec
@@ -0,0 +1,304 @@
+%global _empty_manifest_terminate_build 0
+Name: python-patchify
+Version: 0.2.3
+Release: 1
+Summary: A library that helps you split image into small, overlappable patches, and merge patches back into the original image.
+License: MIT
+URL: https://github.com/dovahcrow/patchify.py
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/79/b7/1b281a31d8fdbdfc44af2fcb7a0750158e160f3a8c608fcb602e62be24a8/patchify-0.2.3.tar.gz
+BuildArch: noarch
+
+Requires: python3-numpy
+
+%description
+# patchify
+
+patchfy can split images into small overlappable patches by given patch cell size, and merge patches into original image.
+
+This library provides two functions: `patchify`, `unpatchify`.
+
+## Installation
+```
+pip install patchify
+```
+
+## Usage
+
+### Split image to patches
+
+`patchify(image_to_patch, patch_shape, step=1)`
+
+2D image:
+```python
+#This will split the image into small images of shape [3,3]
+patches = patchify(image, (3, 3), step=1)
+```
+
+3D image:
+```python
+#This will split the image into small images of shape [3,3,3]
+patches = patchify(image, (3, 3, 3), step=1)
+```
+
+### Merge patches into original image
+
+`unpatchify(patches_to_merge, merged_image_size)`
+
+```python
+reconstructed_image = unpatchify(patches, image.shape)
+```
+This will reconstruct the original image that was patchified in previous code.
+
+**Caveat**: in order for `unpatchify` to work, you need to create patchies with equal step size. e.g. if the original image has width 3 and the patch has width 2, you cannot really create equal step size patches with step size 2. (first patch [elem0, elem1] and second patch [elem2, elem3], which is out of bound).
+
+The required condition for unpatchify to success is to have (width - patch_width) mod step_size = 0.
+
+### Full running examples
+
+#### 2D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
+
+patches = patchify(image, (2,2), step=1) # split image into 2*3 small 2*2 patches.
+
+assert patches.shape == (2, 3, 2, 2)
+reconstructed_image = unpatchify(patches, image.shape)
+
+assert (reconstructed_image == image).all()
+```
+
+#### 3D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.random.rand(512,512,3)
+
+patches = patchify(image, (2,2,3), step=1) # patch shape [2,2,3]
+print(patches.shape) # (511, 511, 1, 2, 2, 3). Total patches created: 511x511x1
+
+assert patches.shape == (511, 511, 1, 2, 2, 3)
+reconstructed_image = unpatchify(patches, image.shape)
+print(reconstructed_image.shape) # (512, 512, 3)
+
+assert (reconstructed_image == image).all()
+```
+
+
+%package -n python3-patchify
+Summary: A library that helps you split image into small, overlappable patches, and merge patches back into the original image.
+Provides: python-patchify
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-patchify
+# patchify
+
+patchfy can split images into small overlappable patches by given patch cell size, and merge patches into original image.
+
+This library provides two functions: `patchify`, `unpatchify`.
+
+## Installation
+```
+pip install patchify
+```
+
+## Usage
+
+### Split image to patches
+
+`patchify(image_to_patch, patch_shape, step=1)`
+
+2D image:
+```python
+#This will split the image into small images of shape [3,3]
+patches = patchify(image, (3, 3), step=1)
+```
+
+3D image:
+```python
+#This will split the image into small images of shape [3,3,3]
+patches = patchify(image, (3, 3, 3), step=1)
+```
+
+### Merge patches into original image
+
+`unpatchify(patches_to_merge, merged_image_size)`
+
+```python
+reconstructed_image = unpatchify(patches, image.shape)
+```
+This will reconstruct the original image that was patchified in previous code.
+
+**Caveat**: in order for `unpatchify` to work, you need to create patchies with equal step size. e.g. if the original image has width 3 and the patch has width 2, you cannot really create equal step size patches with step size 2. (first patch [elem0, elem1] and second patch [elem2, elem3], which is out of bound).
+
+The required condition for unpatchify to success is to have (width - patch_width) mod step_size = 0.
+
+### Full running examples
+
+#### 2D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
+
+patches = patchify(image, (2,2), step=1) # split image into 2*3 small 2*2 patches.
+
+assert patches.shape == (2, 3, 2, 2)
+reconstructed_image = unpatchify(patches, image.shape)
+
+assert (reconstructed_image == image).all()
+```
+
+#### 3D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.random.rand(512,512,3)
+
+patches = patchify(image, (2,2,3), step=1) # patch shape [2,2,3]
+print(patches.shape) # (511, 511, 1, 2, 2, 3). Total patches created: 511x511x1
+
+assert patches.shape == (511, 511, 1, 2, 2, 3)
+reconstructed_image = unpatchify(patches, image.shape)
+print(reconstructed_image.shape) # (512, 512, 3)
+
+assert (reconstructed_image == image).all()
+```
+
+
+%package help
+Summary: Development documents and examples for patchify
+Provides: python3-patchify-doc
+%description help
+# patchify
+
+patchfy can split images into small overlappable patches by given patch cell size, and merge patches into original image.
+
+This library provides two functions: `patchify`, `unpatchify`.
+
+## Installation
+```
+pip install patchify
+```
+
+## Usage
+
+### Split image to patches
+
+`patchify(image_to_patch, patch_shape, step=1)`
+
+2D image:
+```python
+#This will split the image into small images of shape [3,3]
+patches = patchify(image, (3, 3), step=1)
+```
+
+3D image:
+```python
+#This will split the image into small images of shape [3,3,3]
+patches = patchify(image, (3, 3, 3), step=1)
+```
+
+### Merge patches into original image
+
+`unpatchify(patches_to_merge, merged_image_size)`
+
+```python
+reconstructed_image = unpatchify(patches, image.shape)
+```
+This will reconstruct the original image that was patchified in previous code.
+
+**Caveat**: in order for `unpatchify` to work, you need to create patchies with equal step size. e.g. if the original image has width 3 and the patch has width 2, you cannot really create equal step size patches with step size 2. (first patch [elem0, elem1] and second patch [elem2, elem3], which is out of bound).
+
+The required condition for unpatchify to success is to have (width - patch_width) mod step_size = 0.
+
+### Full running examples
+
+#### 2D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
+
+patches = patchify(image, (2,2), step=1) # split image into 2*3 small 2*2 patches.
+
+assert patches.shape == (2, 3, 2, 2)
+reconstructed_image = unpatchify(patches, image.shape)
+
+assert (reconstructed_image == image).all()
+```
+
+#### 3D image patchify and merge
+
+```python
+import numpy as np
+from patchify import patchify, unpatchify
+
+image = np.random.rand(512,512,3)
+
+patches = patchify(image, (2,2,3), step=1) # patch shape [2,2,3]
+print(patches.shape) # (511, 511, 1, 2, 2, 3). Total patches created: 511x511x1
+
+assert patches.shape == (511, 511, 1, 2, 2, 3)
+reconstructed_image = unpatchify(patches, image.shape)
+print(reconstructed_image.shape) # (512, 512, 3)
+
+assert (reconstructed_image == image).all()
+```
+
+
+%prep
+%autosetup -n patchify-0.2.3
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-patchify -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.3-1
+- Package Spec generated