Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Oleh Astappiev
Near-Similar Image Recognition
Commits
e0bd938e
Commit
e0bd938e
authored
Jan 26, 2022
by
Oleh Astappiev
Browse files
fix: resize images properly
parent
26d3fad4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
src/images.py
src/images.py
+21
-4
src/utils/common.py
src/utils/common.py
+3
-2
No files found.
src/images.py
View file @
e0bd938e
...
...
@@ -13,12 +13,29 @@ cifar10_images = np.concatenate([train_images, test_images])
cifar10_labels
=
np
.
concatenate
([
train_labels
,
test_labels
])
cifar10_vds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
cifar10_images
,
cifar10_labels
))
def
print_resized
(
dataset
):
plt
.
figure
(
figsize
=
(
20
,
20
))
for
i
,
(
image
,
label
)
in
enumerate
(
dataset
.
take
(
3
)):
img_cv2
=
cv2
.
resize
(
image
.
numpy
(),
target_shape
)
# img_tf = tf.image.per_image_standardization(image)
img_tf
=
tf
.
image
.
resize
(
image
,
target_shape
,
method
=
tf
.
image
.
ResizeMethod
.
NEAREST_NEIGHBOR
)
img_tf
=
tf
.
cast
(
img_tf
,
tf
.
uint8
)
# img_tf = tf.image.convert_image_dtype(img_tf, dtype=tf.uint8, saturate=False)
subplot_image
(
3
,
3
,
i
*
3
+
1
,
image
.
numpy
(),
"Original image"
)
subplot_image
(
3
,
3
,
i
*
3
+
2
,
img_cv2
,
"CV2 image"
)
subplot_image
(
3
,
3
,
i
*
3
+
3
,
img_tf
.
numpy
(),
"TF image"
)
plt
.
show
()
print_resized
(
cifar10_vds
)
# test HSV
print
(
'test HSV'
)
plot_hsv
(
cifar10_vds
)
#
print('test HSV')
#
plot_hsv(cifar10_vds)
print
(
'test SIFT'
)
plot_sift
(
cifar10_vds
)
#
print('test SIFT')
#
plot_sift(cifar10_vds)
# 906, 1692, 1711, 2610, 3259, 3418, 3789, 4277, 4975, 5010, 5255, 5867, 5988, 6406, 7089, 7365, 8072
# 8443, 8998, 9008, 9323, 9664, 9881, 9903, 9985, 10095, 11650, 13043, 13075, 13841, 14698, 15443
...
...
src/utils/common.py
View file @
e0bd938e
...
...
@@ -15,9 +15,10 @@ def process_images_couple(image, label):
def
process_images
(
image
):
# Normalize images to have a mean of 0 and standard deviation of 1
image
=
tf
.
image
.
per_image_standardization
(
image
)
#
image = tf.image.per_image_standardization(image)
# Resize images from 32x32 to 277x277
image
=
tf
.
image
.
resize
(
image
,
target_shape
)
image
=
tf
.
image
.
resize
(
image
,
target_shape
,
method
=
tf
.
image
.
ResizeMethod
.
NEAREST_NEIGHBOR
)
image
=
tf
.
cast
(
image
,
tf
.
uint8
)
return
image
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment