vislearnlabpy 0.0.2.2__tar.gz → 0.0.2.3__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.
- {vislearnlabpy-0.0.2.2/src/vislearnlabpy.egg-info → vislearnlabpy-0.0.2.3}/PKG-INFO +1 -1
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/pyproject.toml +1 -1
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/stimuli_loader.py +89 -18
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3/src/vislearnlabpy.egg-info}/PKG-INFO +1 -1
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/LICENSE +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/README.md +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/setup.cfg +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/__init__.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/drawings/drawing.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/drawings/svg_render_helpers.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/embedding_store.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/generate_embeddings.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/similarity_generator.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/similarity_utils.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/utils.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/extractions/drawingtask_extractor.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/extractions/mongo_extractor.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/models/clip_model.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/models/feature_generator.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/models/multimodal_model.py +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy.egg-info/SOURCES.txt +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy.egg-info/dependency_links.txt +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy.egg-info/requires.txt +0 -0
- {vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy.egg-info/top_level.txt +0 -0
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/stimuli_loader.py
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
import os
|
|
2
3
|
import pandas as pd
|
|
3
4
|
import re
|
|
@@ -12,10 +13,20 @@ import numpy as np
|
|
|
12
13
|
|
|
13
14
|
random.seed(2)
|
|
14
15
|
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ImgExtractionSettings:
|
|
19
|
+
resize_dim: int = 256
|
|
20
|
+
crop_dim: int = 224
|
|
21
|
+
apply_content_crop: bool = True
|
|
22
|
+
apply_center_crop: bool = False
|
|
23
|
+
use_thumbnail: bool = False
|
|
24
|
+
change_stroke_color: bool = False
|
|
25
|
+
stroke_color: tuple = (0, 0, 0)
|
|
26
|
+
stroke_threshold: int = 200
|
|
27
|
+
|
|
28
|
+
|
|
15
29
|
class ImageExtractor:
|
|
16
|
-
def __init__(self):
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
30
|
@staticmethod
|
|
20
31
|
def RGBA2RGB(img, background_color=(255, 255, 255)):
|
|
21
32
|
"""Alpha composite an RGBA Image with a specified color.
|
|
@@ -42,6 +53,41 @@ class ImageExtractor:
|
|
|
42
53
|
img = img.convert('RGB')
|
|
43
54
|
return img
|
|
44
55
|
|
|
56
|
+
@staticmethod
|
|
57
|
+
def change_stroke_color(img, target_color=(0, 0, 0), threshold=200):
|
|
58
|
+
"""
|
|
59
|
+
Change the color of strokes/dark pixels in an image.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
img -- PIL Image object
|
|
63
|
+
target_color -- Tuple (r, g, b) for the new stroke color
|
|
64
|
+
threshold -- Brightness threshold to identify strokes (0-255)
|
|
65
|
+
Pixels darker than this are considered strokes
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
PIL Image with recolored strokes
|
|
69
|
+
"""
|
|
70
|
+
# Convert to RGBA if not already
|
|
71
|
+
if img.mode != 'RGBA':
|
|
72
|
+
img = img.convert('RGBA')
|
|
73
|
+
|
|
74
|
+
# Convert to numpy array
|
|
75
|
+
img_array = np.array(img)
|
|
76
|
+
|
|
77
|
+
# Calculate brightness (average of RGB channels)
|
|
78
|
+
brightness = img_array[:, :, :3].mean(axis=2)
|
|
79
|
+
|
|
80
|
+
# Create mask for stroke pixels (darker than threshold)
|
|
81
|
+
stroke_mask = brightness < threshold
|
|
82
|
+
|
|
83
|
+
# Apply new color to stroke pixels while preserving alpha
|
|
84
|
+
result = img_array.copy()
|
|
85
|
+
result[stroke_mask, 0] = target_color[0] # R
|
|
86
|
+
result[stroke_mask, 1] = target_color[1] # G
|
|
87
|
+
result[stroke_mask, 2] = target_color[2] # B
|
|
88
|
+
|
|
89
|
+
return Image.fromarray(result)
|
|
90
|
+
|
|
45
91
|
@staticmethod
|
|
46
92
|
def crop_to_content(img, apply_content_crop):
|
|
47
93
|
"""Crop image to remove white space around content."""
|
|
@@ -67,41 +113,45 @@ class ImageExtractor:
|
|
|
67
113
|
return img
|
|
68
114
|
|
|
69
115
|
@staticmethod
|
|
70
|
-
def get_transformations(
|
|
116
|
+
def get_transformations(settings: ImgExtractionSettings=ImgExtractionSettings()):
|
|
71
117
|
"""Load image transformations for dataloader.
|
|
72
118
|
|
|
73
119
|
Args:
|
|
74
|
-
|
|
75
|
-
crop_dim: Dimension for center crop (default 224)
|
|
76
|
-
apply_content_crop: Whether to crop to content (default True)
|
|
77
|
-
apply_center_crop: Whether to apply center crop (default True)
|
|
78
|
-
use_thumbnail: Whether to use thumbnail resizing instead of regular resize (default False)
|
|
120
|
+
settings: ImgExtractionSettings dataclass instance
|
|
79
121
|
"""
|
|
80
122
|
|
|
81
123
|
def combined_transform(image):
|
|
82
124
|
# Step 1: Apply thumbnail resizing if requested
|
|
83
|
-
if use_thumbnail:
|
|
84
|
-
image.thumbnail((resize_dim, resize_dim), Image.Resampling.LANCZOS)
|
|
125
|
+
if settings.use_thumbnail:
|
|
126
|
+
image.thumbnail((settings.resize_dim, settings.resize_dim), Image.Resampling.LANCZOS)
|
|
85
127
|
|
|
86
|
-
# Step 2:
|
|
128
|
+
# Step 2: Change stroke color if enabled (before converting to RGB)
|
|
129
|
+
if settings.change_stroke_color:
|
|
130
|
+
image = ImageExtractor.change_stroke_color(
|
|
131
|
+
image,
|
|
132
|
+
settings.stroke_color,
|
|
133
|
+
settings.stroke_threshold
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Step 3: Convert RGBA to RGB
|
|
87
137
|
img_rgb = ImageExtractor.RGBA2RGB(image)
|
|
88
138
|
|
|
89
|
-
# Step
|
|
90
|
-
img_cropped = ImageExtractor.crop_to_content(img_rgb, apply_content_crop)
|
|
139
|
+
# Step 4: Crop to content (remove whitespace) if enabled
|
|
140
|
+
img_cropped = ImageExtractor.crop_to_content(img_rgb, settings.apply_content_crop)
|
|
91
141
|
return img_cropped
|
|
92
142
|
|
|
93
143
|
# Build transformation pipeline
|
|
94
144
|
transform_list = []
|
|
95
145
|
|
|
96
146
|
# Only add regular resize if not using thumbnail
|
|
97
|
-
if not use_thumbnail:
|
|
147
|
+
if not settings.use_thumbnail:
|
|
98
148
|
# resize first
|
|
99
|
-
transform_list.append(transforms.Resize(resize_dim))
|
|
149
|
+
transform_list.append(transforms.Resize(settings.resize_dim))
|
|
100
150
|
|
|
101
151
|
transform_list.append(transforms.Lambda(combined_transform))
|
|
102
152
|
|
|
103
|
-
if apply_center_crop:
|
|
104
|
-
transform_list.append(transforms.CenterCrop(crop_dim))
|
|
153
|
+
if settings.apply_center_crop:
|
|
154
|
+
transform_list.append(transforms.CenterCrop(settings.crop_dim))
|
|
105
155
|
|
|
106
156
|
# Add any additional transforms you might need
|
|
107
157
|
#transform_list.extend([
|
|
@@ -111,6 +161,27 @@ class ImageExtractor:
|
|
|
111
161
|
|
|
112
162
|
return transforms.Compose(transform_list)
|
|
113
163
|
|
|
164
|
+
@staticmethod
|
|
165
|
+
def save_transformed(original_file, new_file, settings: ImgExtractionSettings = None, transform=None):
|
|
166
|
+
"""
|
|
167
|
+
Load, transform, and save an image.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
original_file: Path to input image
|
|
171
|
+
new_file: Path to save output image
|
|
172
|
+
settings: ImgExtractionSettings dataclass instance (if None, uses default)
|
|
173
|
+
transform: Custom transform (if provided, overrides settings)
|
|
174
|
+
"""
|
|
175
|
+
if settings is None:
|
|
176
|
+
settings = ImgExtractionSettings()
|
|
177
|
+
|
|
178
|
+
if transform is None:
|
|
179
|
+
transform = ImageExtractor.get_transformations(settings)
|
|
180
|
+
|
|
181
|
+
image_data = Image.open(original_file)
|
|
182
|
+
img = transform(image_data)
|
|
183
|
+
img.save(new_file)
|
|
184
|
+
|
|
114
185
|
class StimuliDataset(Dataset):
|
|
115
186
|
def __init__(self, manifest, images_folder=None, id_column=None, transform=None):
|
|
116
187
|
self.manifest = manifest
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/drawings/svg_render_helpers.py
RENAMED
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/embedding_store.py
RENAMED
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/generate_embeddings.py
RENAMED
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/similarity_generator.py
RENAMED
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/embeddings/similarity_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/extractions/mongo_extractor.py
RENAMED
|
File without changes
|
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/models/feature_generator.py
RENAMED
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy/models/multimodal_model.py
RENAMED
|
File without changes
|
|
File without changes
|
{vislearnlabpy-0.0.2.2 → vislearnlabpy-0.0.2.3}/src/vislearnlabpy.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|