pystashx 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pystash/__init__.py +1 -0
- pystash/cli.py +126 -0
- pystash/templates/DIP/Image.jpg +0 -0
- pystash/templates/DIP/__init__.py +1 -0
- pystash/templates/DIP/dft.py +17 -0
- pystash/templates/DIP/greyscale.py +11 -0
- pystash/templates/DIP/noise.py +23 -0
- pystash/templates/DIP/rghscmy.py +16 -0
- pystash/templates/DIP/sampling.py +11 -0
- pystash/templates/DIP/sobel_prewitt.py +18 -0
- pystash/templates/__init__.py +1 -0
- pystashx-0.1.0.dist-info/METADATA +11 -0
- pystashx-0.1.0.dist-info/RECORD +15 -0
- pystashx-0.1.0.dist-info/WHEEL +4 -0
- pystashx-0.1.0.dist-info/entry_points.txt +3 -0
pystash/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# pystash package
|
pystash/cli.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pystash CLI — Interactive two-level menu to extract template scripts.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
$ pystash
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
from importlib.resources import files
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _natural_key(text):
|
|
16
|
+
"""Sort strings containing numbers in human/numerical order (e.g. q1 before q10)."""
|
|
17
|
+
return [int(c) if c.isdigit() else c.lower() for c in re.split(r"(\d+)", text)]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _get_templates_root():
|
|
21
|
+
"""Return a Traversable pointing at the bundled templates/ directory."""
|
|
22
|
+
return files("pystash") / "templates"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _list_subdirs(root):
|
|
26
|
+
"""Return sorted list of subdirectory names inside *root*."""
|
|
27
|
+
return sorted(
|
|
28
|
+
item.name
|
|
29
|
+
for item in root.iterdir()
|
|
30
|
+
if item.is_dir() and not item.name.startswith("__")
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _list_py_files(folder):
|
|
35
|
+
"""Return numerically sorted list of .py filenames inside a Traversable *folder*."""
|
|
36
|
+
return sorted(
|
|
37
|
+
(
|
|
38
|
+
item.name
|
|
39
|
+
for item in folder.iterdir()
|
|
40
|
+
if item.is_file()
|
|
41
|
+
and item.name.endswith(".py")
|
|
42
|
+
and item.name != "__init__.py"
|
|
43
|
+
),
|
|
44
|
+
key=_natural_key,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _extract_file(source, dest_dir):
|
|
49
|
+
"""Copy a single Traversable file into *dest_dir* using shutil.copy."""
|
|
50
|
+
dest_path = os.path.join(dest_dir, source.name)
|
|
51
|
+
with open(dest_path, "wb") as out, source.open("rb") as inp:
|
|
52
|
+
shutil.copyfileobj(inp, out)
|
|
53
|
+
return dest_path
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def copy_programs():
|
|
57
|
+
"""Entry-point: two-level interactive menu -> extract scripts to cwd."""
|
|
58
|
+
templates = _get_templates_root()
|
|
59
|
+
categories = _list_subdirs(templates)
|
|
60
|
+
|
|
61
|
+
if not categories:
|
|
62
|
+
print("\n[!] No template categories found inside the package.")
|
|
63
|
+
print(" Add subdirectories to src/pystash/templates/ and rebuild.")
|
|
64
|
+
sys.exit(1)
|
|
65
|
+
|
|
66
|
+
# -- Level 1 : Folder Selection ---------------------------------------
|
|
67
|
+
print("\n+======================================+")
|
|
68
|
+
print("| PyStash -- Templates |")
|
|
69
|
+
print("+======================================+")
|
|
70
|
+
print("\nAvailable categories:\n")
|
|
71
|
+
for idx, name in enumerate(categories, start=1):
|
|
72
|
+
print(f" [{idx}] {name}")
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
choice = int(input("\n>> Select a category number: "))
|
|
76
|
+
if choice < 1 or choice > len(categories):
|
|
77
|
+
raise ValueError
|
|
78
|
+
except (ValueError, EOFError):
|
|
79
|
+
print("[X] Invalid selection. Exiting.")
|
|
80
|
+
sys.exit(1)
|
|
81
|
+
|
|
82
|
+
selected_category = categories[choice - 1]
|
|
83
|
+
folder = templates / selected_category
|
|
84
|
+
|
|
85
|
+
# -- Level 2 : File Selection -----------------------------------------
|
|
86
|
+
py_files = _list_py_files(folder)
|
|
87
|
+
|
|
88
|
+
if not py_files:
|
|
89
|
+
print(f"\n[!] No .py files found in '{selected_category}/'.")
|
|
90
|
+
print(" Drop your scripts into that folder and rebuild the package.")
|
|
91
|
+
sys.exit(1)
|
|
92
|
+
|
|
93
|
+
print(f"\n-- Scripts in {selected_category}/ --\n")
|
|
94
|
+
print(" [0] => Extract ALL programs from this folder")
|
|
95
|
+
for idx, fname in enumerate(py_files, start=1):
|
|
96
|
+
print(f" [{idx}] {fname}")
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
file_choice = int(input("\n>> Select a file number (0 for all): "))
|
|
100
|
+
if file_choice < 0 or file_choice > len(py_files):
|
|
101
|
+
raise ValueError
|
|
102
|
+
except (ValueError, EOFError):
|
|
103
|
+
print("[X] Invalid selection. Exiting.")
|
|
104
|
+
sys.exit(1)
|
|
105
|
+
|
|
106
|
+
dest_dir = os.getcwd()
|
|
107
|
+
|
|
108
|
+
if file_choice == 0:
|
|
109
|
+
# Extract every .py file in the chosen category
|
|
110
|
+
print()
|
|
111
|
+
for fname in py_files:
|
|
112
|
+
src = folder / fname
|
|
113
|
+
path = _extract_file(src, dest_dir)
|
|
114
|
+
print(f" [+] Extracted: {fname} -> {path}")
|
|
115
|
+
print(f"\n[OK] All {len(py_files)} file(s) from '{selected_category}/' extracted to:\n {dest_dir}")
|
|
116
|
+
else:
|
|
117
|
+
# Extract a single file
|
|
118
|
+
fname = py_files[file_choice - 1]
|
|
119
|
+
src = folder / fname
|
|
120
|
+
path = _extract_file(src, dest_dir)
|
|
121
|
+
print(f"\n [+] Extracted: {fname} -> {path}")
|
|
122
|
+
print(f"\n[OK] File extracted to:\n {dest_dir}")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
copy_programs()
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# DIP — Digital Image Processing templates
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
img = cv2.imread("image.jpg", 0)
|
|
5
|
+
|
|
6
|
+
f = np.fft.fftshift(np.fft.fft2(img))
|
|
7
|
+
mag = 20 * np.log(np.abs(f) + 1)
|
|
8
|
+
m_norm = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)
|
|
9
|
+
|
|
10
|
+
inv = np.fft.ifft2(np.fft.ifftshift(f)).real
|
|
11
|
+
i_norm = np.clip(inv, 0, 255).astype(np.uint8)
|
|
12
|
+
|
|
13
|
+
cv2.imshow("Original", img)
|
|
14
|
+
cv2.imshow("DFT", m_norm)
|
|
15
|
+
cv2.imshow("Inverse DFT", i_norm)
|
|
16
|
+
cv2.waitKey(0)
|
|
17
|
+
cv2.destroyAllWindows()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
img = cv2.imread("image.jpg", 0).astype(float)
|
|
5
|
+
sp = img.copy()
|
|
6
|
+
r = np.random.rand(*img.shape)
|
|
7
|
+
sp[r < 0.02], sp[r > 0.98] = 0, 255
|
|
8
|
+
|
|
9
|
+
noises = [
|
|
10
|
+
img + np.random.normal(0, 25, img.shape),
|
|
11
|
+
sp,
|
|
12
|
+
img + np.random.rayleigh(20, img.shape),
|
|
13
|
+
img + np.random.gamma(2, 10, img.shape),
|
|
14
|
+
img + np.random.exponential(20, img.shape),
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
for x, name in zip(noises, ["Gaussian", "Salt-Pepper", "Rayleigh", "Gamma", "Exponential"]):
|
|
18
|
+
x = np.uint8(np.clip(x, 0, 255))
|
|
19
|
+
cv2.imshow(name, x)
|
|
20
|
+
cv2.imshow(name + " Mean", cv2.blur(x, (3, 3)))
|
|
21
|
+
|
|
22
|
+
cv2.waitKey(0)
|
|
23
|
+
cv2.destroyAllWindows()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
|
|
3
|
+
img = cv2.imread("image.jpg")
|
|
4
|
+
b, g, r = cv2.split(img)
|
|
5
|
+
cmy = 255 - img
|
|
6
|
+
hsi = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
|
7
|
+
|
|
8
|
+
cv2.imshow("Original Image", img)
|
|
9
|
+
cv2.imshow("Blue Channel", cv2.merge([b, g * 0, r * 0]))
|
|
10
|
+
cv2.imshow("Green Channel", cv2.merge([b * 0, g, r * 0]))
|
|
11
|
+
cv2.imshow("Red Channel", cv2.merge([b * 0, g * 0, r]))
|
|
12
|
+
cv2.imshow("CMY Image", cmy)
|
|
13
|
+
cv2.imshow("HSI Image", hsi)
|
|
14
|
+
|
|
15
|
+
cv2.waitKey(0)
|
|
16
|
+
cv2.destroyAllWindows()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
img = cv2.imread("image.jpg", 0)
|
|
5
|
+
|
|
6
|
+
sx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
|
|
7
|
+
sy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
|
|
8
|
+
s = cv2.convertScaleAbs(cv2.magnitude(sx, sy))
|
|
9
|
+
|
|
10
|
+
k = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
|
|
11
|
+
p = cv2.filter2D(img, cv2.CV_32F, k)
|
|
12
|
+
q = cv2.filter2D(img, cv2.CV_32F, k.T)
|
|
13
|
+
t = cv2.convertScaleAbs(cv2.magnitude(p, q))
|
|
14
|
+
|
|
15
|
+
cv2.imshow("Sobel", s)
|
|
16
|
+
cv2.imshow("Prewitt", t)
|
|
17
|
+
cv2.waitKey(0)
|
|
18
|
+
cv2.destroyAllWindows()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# This file marks templates/ as a Python package so importlib.resources can traverse it.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pystashx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Interactive CLI to extract categorized Python script templates into your working directory.
|
|
5
|
+
Author: Anonymous
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Requires-Dist: matplotlib
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: opencv-python-headless
|
|
11
|
+
Requires-Dist: scipy
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pystash/__init__.py,sha256=9zsAzsFgjecb55uaTlWyiI3usMLfD3s3jkP-HLOrbzw,18
|
|
2
|
+
pystash/cli.py,sha256=E1WnsxPOot4mIdsbtu1WWhCFg0w5u996FlG_45TSunw,4042
|
|
3
|
+
pystash/templates/__init__.py,sha256=LC9s5JtsJR0pCiV05VdwECWe3cgJXxWbjbBDYlunsDs,89
|
|
4
|
+
pystash/templates/DIP/Image.jpg,sha256=8GUlNcA7eWr8c-XmYRqpKxIb9AS_YbRw_sQjJM8Qgw4,48735
|
|
5
|
+
pystash/templates/DIP/__init__.py,sha256=GojToSl1rlo7zESo0HsORfwgMti9JUGjcKmRSHFOfIs,45
|
|
6
|
+
pystash/templates/DIP/dft.py,sha256=1iMXxmXit3kQIR81BugN89rJyNejwKMLFXourmCeFKU,433
|
|
7
|
+
pystash/templates/DIP/greyscale.py,sha256=CFVrf2NaJJI8S1CcaYZIpu3Z-CJktyrkhgh-zvnl6T0,229
|
|
8
|
+
pystash/templates/DIP/noise.py,sha256=i_9nDBi0P_p5Giek7HSipg-uh67tQovOnBIjSCQocts,614
|
|
9
|
+
pystash/templates/DIP/rghscmy.py,sha256=rGPDlwhQ6t14Nn3mE7ULm-hgyYtwG5h2aKsamH5Q_mE,430
|
|
10
|
+
pystash/templates/DIP/sampling.py,sha256=tgzmVLteI0L0NeL7QvOV6_gaFsJAPu-QGvaSvqqpowQ,220
|
|
11
|
+
pystash/templates/DIP/sobel_prewitt.py,sha256=looMjt3ziuxUQQeM92QZ615Jomape-PdtecjOgh-1kI,449
|
|
12
|
+
pystashx-0.1.0.dist-info/METADATA,sha256=3JHqabVVYSQw58dTB21ulwSeNtfpnEfDZzJnaFdEG0Y,324
|
|
13
|
+
pystashx-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
14
|
+
pystashx-0.1.0.dist-info/entry_points.txt,sha256=JivIJxL1UGZgR8WjhdtN3HTJ07Gf8FFaW4cu-RYxE4U,91
|
|
15
|
+
pystashx-0.1.0.dist-info/RECORD,,
|