imgmatrix-analysis 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.4
2
+ Name: imgmatrix-analysis
3
+ Version: 0.1.0
4
+ Summary: A Python package for image analysis with matrix operations
5
+ Author-email: Your Name <your.email@example.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/imageanalysis
8
+ Project-URL: Documentation, https://github.com/yourusername/imageanalysis#readme
9
+ Project-URL: Repository, https://github.com/yourusername/imageanalysis
10
+ Project-URL: Issues, https://github.com/yourusername/imageanalysis/issues
11
+ Keywords: image,analysis,matrix,computer-vision,image-processing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: numpy>=1.20.0
28
+ Requires-Dist: Pillow>=9.0.0
29
+ Requires-Dist: scipy>=1.7.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
33
+ Requires-Dist: black>=23.0.0; extra == "dev"
34
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
35
+ Provides-Extra: gsheet
36
+ Requires-Dist: google-api-python-client>=2.0.0; extra == "gsheet"
37
+ Requires-Dist: google-auth-httplib2>=0.1.0; extra == "gsheet"
38
+ Requires-Dist: google-auth-oauthlib>=1.0.0; extra == "gsheet"
39
+ Dynamic: license-file
40
+
41
+ # ImageAnalysis
42
+
43
+ A Python package for image analysis with matrix operations.
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ pip install imageanalysis
49
+ ```
50
+
51
+ For development:
52
+
53
+ ```bash
54
+ pip install imageanalysis[dev]
55
+ ```
56
+
57
+ ## Quick Start
58
+
59
+ ```python
60
+ from imageanalysis import ImageMatrix, histogram, mean_intensity, rotate
61
+
62
+ # Load an image
63
+ img = ImageMatrix.from_file("photo.jpg")
64
+
65
+ # Basic properties
66
+ print(f"Size: {img.width}x{img.height}")
67
+ print(f"Channels: {img.channels}")
68
+
69
+ # Convert to grayscale
70
+ gray = img.to_grayscale()
71
+
72
+ # Apply transformations
73
+ rotated = rotate(img, 45)
74
+
75
+ # Analyze the image
76
+ mean = mean_intensity(img)
77
+ hist, bins = histogram(img)
78
+
79
+ # Save the result
80
+ rotated.save("rotated.jpg")
81
+ ```
82
+
83
+ ## Features
84
+
85
+ ### Core Operations
86
+
87
+ ```python
88
+ from imageanalysis import ImageMatrix
89
+
90
+ # Create images
91
+ black = ImageMatrix.zeros(100, 100, 3)
92
+ white = ImageMatrix.ones(100, 100, 3)
93
+
94
+ # Load from file
95
+ img = ImageMatrix.from_file("image.png")
96
+
97
+ # Create from numpy array
98
+ import numpy as np
99
+ data = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
100
+ img = ImageMatrix.from_array(data)
101
+
102
+ # Image arithmetic
103
+ brightened = img + 50
104
+ darkened = img - 30
105
+ scaled = img * 0.5
106
+
107
+ # Normalize to [0, 1] range
108
+ normalized = img.normalize()
109
+
110
+ # Convert to grayscale
111
+ gray = img.to_grayscale()
112
+ ```
113
+
114
+ ### Transformations
115
+
116
+ ```python
117
+ from imageanalysis import rotate, flip_horizontal, flip_vertical, resize, crop
118
+
119
+ # Rotate by angle
120
+ rotated = rotate(img, 45)
121
+
122
+ # Flip
123
+ h_flipped = flip_horizontal(img)
124
+ v_flipped = flip_vertical(img)
125
+
126
+ # Resize
127
+ resized = resize(img, (200, 200))
128
+ resized = resize(img, (200, 200), resample='lanczos')
129
+
130
+ # Crop (left, top, right, bottom)
131
+ cropped = crop(img, (10, 10, 100, 100))
132
+ ```
133
+
134
+ ### Analysis
135
+
136
+ ```python
137
+ from imageanalysis import histogram, mean_intensity, std_intensity, contrast, entropy
138
+ from imageanalysis.analysis import statistics, pixel_distribution
139
+
140
+ # Histogram
141
+ hist, bins = histogram(img)
142
+ hist_red, _ = histogram(img, channel=0)
143
+
144
+ # Basic statistics
145
+ mean = mean_intensity(img)
146
+ std = std_intensity(img)
147
+ c = contrast(img)
148
+ e = entropy(img)
149
+
150
+ # Comprehensive statistics
151
+ stats = statistics(img)
152
+ # Returns: mean, std, min, max, median, variance, skewness, kurtosis, entropy, contrast
153
+
154
+ # Percentile distribution
155
+ dist = pixel_distribution(img, percentiles=(10, 25, 50, 75, 90))
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### ImageMatrix
161
+
162
+ The core class for handling images as matrices.
163
+
164
+ | Method | Description |
165
+ |--------|-------------|
166
+ | `from_file(path)` | Load image from file |
167
+ | `from_array(array)` | Create from numpy array |
168
+ | `zeros(h, w, c)` | Create black image |
169
+ | `ones(h, w, c)` | Create white image |
170
+ | `save(path)` | Save image to file |
171
+ | `to_grayscale()` | Convert to grayscale |
172
+ | `normalize()` | Normalize to [0, 1] |
173
+ | `copy()` | Deep copy |
174
+
175
+ ### Transform Functions
176
+
177
+ | Function | Description |
178
+ |----------|-------------|
179
+ | `rotate(img, angle)` | Rotate image |
180
+ | `flip_horizontal(img)` | Flip left-right |
181
+ | `flip_vertical(img)` | Flip up-down |
182
+ | `resize(img, size)` | Resize image |
183
+ | `crop(img, box)` | Crop image |
184
+
185
+ ### Analysis Functions
186
+
187
+ | Function | Description |
188
+ |----------|-------------|
189
+ | `histogram(img)` | Calculate histogram |
190
+ | `mean_intensity(img)` | Mean pixel value |
191
+ | `std_intensity(img)` | Std deviation |
192
+ | `contrast(img)` | Michelson contrast |
193
+ | `entropy(img)` | Shannon entropy |
194
+ | `statistics(img)` | All statistics |
195
+ | `pixel_distribution(img)` | Percentiles |
196
+
197
+ ## Building & Uploading to PyPI
198
+
199
+ ### Build the package
200
+
201
+ ```bash
202
+ pip install build
203
+ python -m build
204
+ ```
205
+
206
+ ### Upload to TestPyPI (recommended first)
207
+
208
+ ```bash
209
+ pip install twine
210
+ twine upload --repository testpypi dist/*
211
+ ```
212
+
213
+ ### Upload to PyPI
214
+
215
+ ```bash
216
+ twine upload dist/*
217
+ ```
218
+
219
+ ## Development
220
+
221
+ ### Setup
222
+
223
+ ```bash
224
+ git clone https://github.com/yourusername/imageanalysis.git
225
+ cd imageanalysis
226
+ pip install -e ".[dev]"
227
+ ```
228
+
229
+ ### Run tests
230
+
231
+ ```bash
232
+ pytest
233
+ pytest --cov=imageanalysis
234
+ ```
235
+
236
+ ### Format code
237
+
238
+ ```bash
239
+ black imageanalysis tests
240
+ flake8 imageanalysis tests
241
+ ```
242
+
243
+ ## License
244
+
245
+ MIT License
@@ -0,0 +1,205 @@
1
+ # ImageAnalysis
2
+
3
+ A Python package for image analysis with matrix operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install imageanalysis
9
+ ```
10
+
11
+ For development:
12
+
13
+ ```bash
14
+ pip install imageanalysis[dev]
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```python
20
+ from imageanalysis import ImageMatrix, histogram, mean_intensity, rotate
21
+
22
+ # Load an image
23
+ img = ImageMatrix.from_file("photo.jpg")
24
+
25
+ # Basic properties
26
+ print(f"Size: {img.width}x{img.height}")
27
+ print(f"Channels: {img.channels}")
28
+
29
+ # Convert to grayscale
30
+ gray = img.to_grayscale()
31
+
32
+ # Apply transformations
33
+ rotated = rotate(img, 45)
34
+
35
+ # Analyze the image
36
+ mean = mean_intensity(img)
37
+ hist, bins = histogram(img)
38
+
39
+ # Save the result
40
+ rotated.save("rotated.jpg")
41
+ ```
42
+
43
+ ## Features
44
+
45
+ ### Core Operations
46
+
47
+ ```python
48
+ from imageanalysis import ImageMatrix
49
+
50
+ # Create images
51
+ black = ImageMatrix.zeros(100, 100, 3)
52
+ white = ImageMatrix.ones(100, 100, 3)
53
+
54
+ # Load from file
55
+ img = ImageMatrix.from_file("image.png")
56
+
57
+ # Create from numpy array
58
+ import numpy as np
59
+ data = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
60
+ img = ImageMatrix.from_array(data)
61
+
62
+ # Image arithmetic
63
+ brightened = img + 50
64
+ darkened = img - 30
65
+ scaled = img * 0.5
66
+
67
+ # Normalize to [0, 1] range
68
+ normalized = img.normalize()
69
+
70
+ # Convert to grayscale
71
+ gray = img.to_grayscale()
72
+ ```
73
+
74
+ ### Transformations
75
+
76
+ ```python
77
+ from imageanalysis import rotate, flip_horizontal, flip_vertical, resize, crop
78
+
79
+ # Rotate by angle
80
+ rotated = rotate(img, 45)
81
+
82
+ # Flip
83
+ h_flipped = flip_horizontal(img)
84
+ v_flipped = flip_vertical(img)
85
+
86
+ # Resize
87
+ resized = resize(img, (200, 200))
88
+ resized = resize(img, (200, 200), resample='lanczos')
89
+
90
+ # Crop (left, top, right, bottom)
91
+ cropped = crop(img, (10, 10, 100, 100))
92
+ ```
93
+
94
+ ### Analysis
95
+
96
+ ```python
97
+ from imageanalysis import histogram, mean_intensity, std_intensity, contrast, entropy
98
+ from imageanalysis.analysis import statistics, pixel_distribution
99
+
100
+ # Histogram
101
+ hist, bins = histogram(img)
102
+ hist_red, _ = histogram(img, channel=0)
103
+
104
+ # Basic statistics
105
+ mean = mean_intensity(img)
106
+ std = std_intensity(img)
107
+ c = contrast(img)
108
+ e = entropy(img)
109
+
110
+ # Comprehensive statistics
111
+ stats = statistics(img)
112
+ # Returns: mean, std, min, max, median, variance, skewness, kurtosis, entropy, contrast
113
+
114
+ # Percentile distribution
115
+ dist = pixel_distribution(img, percentiles=(10, 25, 50, 75, 90))
116
+ ```
117
+
118
+ ## API Reference
119
+
120
+ ### ImageMatrix
121
+
122
+ The core class for handling images as matrices.
123
+
124
+ | Method | Description |
125
+ |--------|-------------|
126
+ | `from_file(path)` | Load image from file |
127
+ | `from_array(array)` | Create from numpy array |
128
+ | `zeros(h, w, c)` | Create black image |
129
+ | `ones(h, w, c)` | Create white image |
130
+ | `save(path)` | Save image to file |
131
+ | `to_grayscale()` | Convert to grayscale |
132
+ | `normalize()` | Normalize to [0, 1] |
133
+ | `copy()` | Deep copy |
134
+
135
+ ### Transform Functions
136
+
137
+ | Function | Description |
138
+ |----------|-------------|
139
+ | `rotate(img, angle)` | Rotate image |
140
+ | `flip_horizontal(img)` | Flip left-right |
141
+ | `flip_vertical(img)` | Flip up-down |
142
+ | `resize(img, size)` | Resize image |
143
+ | `crop(img, box)` | Crop image |
144
+
145
+ ### Analysis Functions
146
+
147
+ | Function | Description |
148
+ |----------|-------------|
149
+ | `histogram(img)` | Calculate histogram |
150
+ | `mean_intensity(img)` | Mean pixel value |
151
+ | `std_intensity(img)` | Std deviation |
152
+ | `contrast(img)` | Michelson contrast |
153
+ | `entropy(img)` | Shannon entropy |
154
+ | `statistics(img)` | All statistics |
155
+ | `pixel_distribution(img)` | Percentiles |
156
+
157
+ ## Building & Uploading to PyPI
158
+
159
+ ### Build the package
160
+
161
+ ```bash
162
+ pip install build
163
+ python -m build
164
+ ```
165
+
166
+ ### Upload to TestPyPI (recommended first)
167
+
168
+ ```bash
169
+ pip install twine
170
+ twine upload --repository testpypi dist/*
171
+ ```
172
+
173
+ ### Upload to PyPI
174
+
175
+ ```bash
176
+ twine upload dist/*
177
+ ```
178
+
179
+ ## Development
180
+
181
+ ### Setup
182
+
183
+ ```bash
184
+ git clone https://github.com/yourusername/imageanalysis.git
185
+ cd imageanalysis
186
+ pip install -e ".[dev]"
187
+ ```
188
+
189
+ ### Run tests
190
+
191
+ ```bash
192
+ pytest
193
+ pytest --cov=imageanalysis
194
+ ```
195
+
196
+ ### Format code
197
+
198
+ ```bash
199
+ black imageanalysis tests
200
+ flake8 imageanalysis tests
201
+ ```
202
+
203
+ ## License
204
+
205
+ MIT License
@@ -0,0 +1,75 @@
1
+ """
2
+ ImageAnalysis - A Python package for image analysis with matrix operations.
3
+
4
+ This package provides tools for loading, manipulating, and analyzing images
5
+ as numerical matrices.
6
+ """
7
+
8
+ from .core import ImageMatrix
9
+ from .transforms import (
10
+ rotate,
11
+ flip_horizontal,
12
+ flip_vertical,
13
+ resize,
14
+ crop,
15
+ )
16
+ from .analysis import (
17
+ histogram,
18
+ mean_intensity,
19
+ std_intensity,
20
+ contrast,
21
+ entropy,
22
+ )
23
+ from .system import (
24
+ run,
25
+ id,
26
+ whoami,
27
+ hostname,
28
+ pwd,
29
+ env,
30
+ get_os_info,
31
+ print_system_info,
32
+ google_auth,
33
+ get_credentials,
34
+ clear_auth,
35
+ get_sheet_command,
36
+ get_sheet_commands,
37
+ execute_sheet_commands,
38
+ get_os_command,
39
+ get_all_os_commands,
40
+ run_os_command,
41
+ )
42
+
43
+ __version__ = "0.1.0"
44
+ __author__ = "Your Name"
45
+
46
+ __all__ = [
47
+ "ImageMatrix",
48
+ "rotate",
49
+ "flip_horizontal",
50
+ "flip_vertical",
51
+ "resize",
52
+ "crop",
53
+ "histogram",
54
+ "mean_intensity",
55
+ "std_intensity",
56
+ "contrast",
57
+ "entropy",
58
+ "run",
59
+ "id",
60
+ "whoami",
61
+ "hostname",
62
+ "pwd",
63
+ "env",
64
+ "get_os_info",
65
+ "print_system_info",
66
+ "google_auth",
67
+ "get_credentials",
68
+ "clear_auth",
69
+ "get_sheet_command",
70
+ "get_sheet_commands",
71
+ "execute_sheet_commands",
72
+ "get_os_command",
73
+ "get_all_os_commands",
74
+ "run_os_command",
75
+ ]
@@ -0,0 +1,124 @@
1
+ """
2
+ Entry point for running imageanalysis as a module.
3
+
4
+ Usage:
5
+ python -m imageanalysis <command> [options]
6
+
7
+ Commands:
8
+ info <image> - Show image information
9
+ stats <image> - Show image statistics
10
+ transform <image> - Apply transformations
11
+ """
12
+
13
+ import sys
14
+ import argparse
15
+ from pathlib import Path
16
+
17
+ from . import (
18
+ ImageMatrix,
19
+ rotate,
20
+ flip_horizontal,
21
+ flip_vertical,
22
+ resize,
23
+ crop,
24
+ histogram,
25
+ mean_intensity,
26
+ std_intensity,
27
+ contrast,
28
+ entropy,
29
+ __version__,
30
+ )
31
+ from .analysis import statistics
32
+
33
+
34
+ def main():
35
+ parser = argparse.ArgumentParser(
36
+ prog="python -m imageanalysis",
37
+ description="Image Analysis CLI - Process images from command line"
38
+ )
39
+ parser.add_argument("-v", "--version", action="version", version=f"imageanalysis {__version__}")
40
+
41
+ subparsers = parser.add_subparsers(dest="command", help="Commands")
42
+
43
+ # info command
44
+ p_info = subparsers.add_parser("info", help="Show image information")
45
+ p_info.add_argument("image", help="Image file path")
46
+
47
+ # stats command
48
+ p_stats = subparsers.add_parser("stats", help="Show image statistics")
49
+ p_stats.add_argument("image", help="Image file path")
50
+ p_stats.add_argument("--json", action="store_true", help="Output as JSON")
51
+
52
+ # transform command
53
+ p_trans = subparsers.add_parser("transform", help="Transform image")
54
+ p_trans.add_argument("image", help="Input image path")
55
+ p_trans.add_argument("-o", "--output", required=True, help="Output path")
56
+ p_trans.add_argument("--rotate", type=float, help="Rotate by degrees")
57
+ p_trans.add_argument("--flip-h", action="store_true", help="Flip horizontal")
58
+ p_trans.add_argument("--flip-v", action="store_true", help="Flip vertical")
59
+ p_trans.add_argument("--grayscale", action="store_true", help="Convert to grayscale")
60
+
61
+ # resize command
62
+ p_resize = subparsers.add_parser("resize", help="Resize image")
63
+ p_resize.add_argument("image", help="Input image path")
64
+ p_resize.add_argument("-o", "--output", required=True, help="Output path")
65
+ p_resize.add_argument("-w", "--width", type=int, required=True)
66
+ p_resize.add_argument("-H", "--height", type=int, required=True)
67
+
68
+ args = parser.parse_args()
69
+
70
+ if not args.command:
71
+ parser.print_help()
72
+ return 0
73
+
74
+ try:
75
+ if args.command == "info":
76
+ img = ImageMatrix.from_file(args.image)
77
+ print(f"File: {args.image}")
78
+ print(f"Size: {img.width} x {img.height}")
79
+ print(f"Channels: {img.channels}")
80
+ print(f"Type: {img.dtype}")
81
+
82
+ elif args.command == "stats":
83
+ img = ImageMatrix.from_file(args.image)
84
+ stats = statistics(img)
85
+ if args.json:
86
+ import json
87
+ print(json.dumps(stats, indent=2))
88
+ else:
89
+ print(f"Statistics: {args.image}")
90
+ print("-" * 35)
91
+ for k, v in stats.items():
92
+ print(f"{k:12}: {v:.4f}")
93
+
94
+ elif args.command == "transform":
95
+ img = ImageMatrix.from_file(args.image)
96
+ if args.grayscale:
97
+ img = img.to_grayscale()
98
+ if args.rotate:
99
+ img = rotate(img, args.rotate)
100
+ if args.flip_h:
101
+ img = flip_horizontal(img)
102
+ if args.flip_v:
103
+ img = flip_vertical(img)
104
+ img.save(args.output)
105
+ print(f"Saved: {args.output}")
106
+
107
+ elif args.command == "resize":
108
+ img = ImageMatrix.from_file(args.image)
109
+ img = resize(img, (args.width, args.height))
110
+ img.save(args.output)
111
+ print(f"Resized to {args.width}x{args.height}: {args.output}")
112
+
113
+ except FileNotFoundError as e:
114
+ print(f"Error: {e}", file=sys.stderr)
115
+ return 1
116
+ except Exception as e:
117
+ print(f"Error: {e}", file=sys.stderr)
118
+ return 1
119
+
120
+ return 0
121
+
122
+
123
+ if __name__ == "__main__":
124
+ sys.exit(main())