Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BachelorDeeplearning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s184400
BachelorDeeplearning
Commits
bf3b1612
Commit
bf3b1612
authored
4 years ago
by
Gustav Als
Browse files
Options
Downloads
Patches
Plain Diff
image_cropping.py test
parent
faf830d8
No related branches found
No related tags found
1 merge request
!2
Prepocessing
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
color_constancy.py
+17
-17
17 additions, 17 deletions
color_constancy.py
image_cropping.py
+12
-10
12 additions, 10 deletions
image_cropping.py
with
29 additions
and
27 deletions
color_constancy.py
+
17
−
17
View file @
bf3b1612
...
...
@@ -234,23 +234,23 @@ def general_color_constancy(image, gaussian_differentiation=0, minkowski_norm=5,
out_image
[
out_image
>=
255
]
=
255
return
white_R
,
white_G
,
white_B
,
out_image
test_img
=
cv2
.
imread
(
r
'
C:\Users\Bruger\Pictures\building1.jpg
'
,
1
)
# test_img = cv2.imread(r'C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\ISIC_0000001.jpg', 1)
im_rgb
=
cv2
.
cvtColor
(
test_img
,
cv2
.
COLOR_BGR2RGB
)
# imtest = np.random.normal(100,10, (250,250,3))
R
,
G
,
B
,
test_img1
=
general_color_constancy
(
im_rgb
,
gaussian_differentiation
=
1
,
minkowski_norm
=
5
,
sigma
=
2
)
fig
=
plt
.
figure
(
figsize
=
(
9
,
12
))
fig
.
add_subplot
(
1
,
2
,
1
)
plt
.
imshow
(
im_rgb
)
fig
.
add_subplot
(
1
,
2
,
2
)
plt
.
imshow
(
test_img1
)
plt
.
show
()
#
#
test_img = cv2.imread(r'C:\Users\Bruger\Pictures\building1.jpg', 1)
#
# test_img = cv2.imread(r'C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\ISIC_0000001.jpg', 1)
#
im_rgb = cv2.cvtColor(test_img, cv2.COLOR_BGR2RGB)
#
# imtest = np.random.normal(100,10, (250,250,3))
#
#
R, G, B, test_img1 = general_color_constancy(im_rgb, gaussian_differentiation=1, minkowski_norm=5, sigma=2)
#
#
fig = plt.figure(figsize=(9,12))
#
fig.add_subplot(1,2,1)
#
plt.imshow(im_rgb)
#
#
fig.add_subplot(1,2,2)
#
plt.imshow(test_img1)
#
#
plt.show()
#
...
...
This diff is collapsed.
Click to expand it.
image_cropping.py
+
12
−
10
View file @
bf3b1612
...
...
@@ -17,13 +17,16 @@ time_zero = time.time()
width
=
600
height
=
450
preserve_size
=
600
paths
=
[
r
'
C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\\
'
]
return_folder
=
r
'
C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\return\\
'
# paths = [r'C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\\']
# return_folder = r'C:\Users\ptrkm\OneDrive\Dokumenter\TestFolder\return\\'
paths
=
[
r
'
C:\Users\Bruger\OneDrive\DTU - General engineering\6. Semester\Bachelor\ISBI2016_ISIC_Part2B_Training_Data\TestRunImages\\
'
]
return_folder
=
r
'
C:\Users\Bruger\OneDrive\DTU - General engineering\6. Semester\Bachelor\ISBI2016_ISIC_Part2B_Training_Data\TestRunImagesOutput\\
'
standard_size
=
np
.
asarray
([
height
,
width
])
preserve_ratio
=
True
margin
=
0.1
crop_black
=
True
threshold
=
0.3
k
=
50
threshold
=
0.7
resize
=
False
use_color_constancy
=
True
write_to_png
=
False
...
...
@@ -51,6 +54,11 @@ for i, j in enumerate(os.listdir(paths[0])):
threshold_level
=
threshold_otsu
(
gray_image
)
gray_image
=
ndimage
.
gaussian_filter
(
gray_image
,
sigma
=
np
.
sqrt
(
2
))
binary_image
=
gray_image
<
threshold_level
n
,
m
,
_
=
image
.
shape
if
np
.
mean
(
binary_image
[
n
//
2
-
k
//
2
:
n
//
2
+
k
//
2
,
0
:
k
])
>
np
.
mean
(
binary_image
[(
n
//
2
-
k
//
2
):
n
//
2
+
k
//
2
,(
m
//
2
-
k
//
2
):
m
//
2
+
k
//
2
]):
binary_image
=
gray_image
>
threshold_level
# We now find features in the binarised blobs
...
...
@@ -66,13 +74,12 @@ for i, j in enumerate(os.listdir(paths[0])):
y_min
=
(
largest_blob
.
centroid
[
0
]
-
radius
+
margin
*
radius
).
astype
(
int
)
y_max
=
(
largest_blob
.
centroid
[
0
]
+
radius
-
margin
*
radius
).
astype
(
int
)
use_cropping
=
True
else
:
use_cropping
=
False
if
x_min
<
0
or
x_max
>
image
.
shape
[
1
]
or
y_min
<
0
or
y_max
>
image
.
shape
[
0
]:
if
len
(
blob_features
)
>
1
:
indices
=
np
.
where
(
np
.
arange
(
len
(
blob_features
))
!=
largest_blob_idx
)[
0
].
astype
(
int
)
without_largest
=
[
blob_features
[
idx
]
for
idx
in
indices
]
second_largest_idx
=
np
.
argmax
(
...
...
@@ -97,11 +104,6 @@ for i, j in enumerate(os.listdir(paths[0])):
mean_outside
=
(
np
.
mean
(
image
[:
y_min
,:,:])
+
np
.
mean
(
image
[
y_min
:
y_max
,:
x_min
,:])
+
np
.
mean
(
image
[
y_max
:,:,:])
+
np
.
mean
(
image
[
y_min
:
y_max
,
x_max
:,:]))
/
4
if
mean_outside
/
mean_inside
<
threshold
:
use_cropping
=
False
if
use_cropping
:
image
=
image
[
y_min
:
y_max
,
x_min
:
x_max
,
:]
if
resize
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment