Skip to content

Commit

Permalink
Merge pull request #18 from ljubicicrobert/develop
Browse files Browse the repository at this point in the history
develop -> master @ v0.3.2.0
  • Loading branch information
ljubicicrobert committed Apr 5, 2022
2 parents 534714c + 228c2e4 commit 5455971
Show file tree
Hide file tree
Showing 11 changed files with 658 additions and 348 deletions.
16 changes: 8 additions & 8 deletions camera_profiles/DJI Mini 2.cpf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
Model = DJI Mini 2

[Intrinsics]
fx = 0.7126984127
fy = 0.7126984127
cx = 0.5067482020
cy = 0.3716643567
fx = 0.7568749675
fy = 0.7568749675
cx = 0.4995236875
cy = 0.49861405333

[Radial]
k1 = 0.0298194
k2 = -0.110242
k1 = -0.00362736
k2 = -0.00130119
k3 = 0.0

[Tangential]
p1 = 0.0007491
p2 = 0.0016115
p1 = 0.000287332
p2 = -0.00220176
2 changes: 1 addition & 1 deletion gui/SSIM Stabilization GUI.application
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>5cQEWx+UnFUAP2k7WHa630JMdqJrtd281T/iVQWAS7w=</dsig:DigestValue>
<dsig:DigestValue>3RPsOZN78HtDmcHYz9R2vEDeiPdk86kuVOnX2XWb9DA=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified gui/SSIM Stabilization GUI.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions gui/SSIM Stabilization GUI.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="SSIM Stabilization GUI.exe" size="354304">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="SSIM Stabilization GUI.exe" size="355840">
<assemblyIdentity name="SSIM Stabilization GUI" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>/v7FKLV31aXlizNnHufDdFIzUxggDtTkrLuWv6dbCP0=</dsig:DigestValue>
<dsig:DigestValue>1SUVMnjos5qUF8w1wPSg2INKvq5fIY0VWlQgF7N6+pQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
8 changes: 4 additions & 4 deletions gui/update.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Updates]
CurrentReleaseTag = v0.3.1.4
CurrentReleaseName = SSIMS_v0.3.1.4
CurrentReleaseDate = 2022-03-11 13:36:03.252079
LastCheckDate = 2022-03-11 13:36:03.252079
CurrentReleaseTag = v0.3.2.0
CurrentReleaseName = SSIMS_v0.3.2.0
CurrentReleaseDate = 2022-04-05 17:57:43.422532
LastCheckDate = 2022-04-05 17:57:43.422532
DisableUpdateCheck = 0
PauseDays = 0

12 changes: 12 additions & 0 deletions release_notes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
SSIMS_v0.3.2.0 ----------------------------------------------------------------

Major changes:
- Added "Explore colorspaces" option in Filter frames form

Minor changes:
- Added new filters and polished old ones
- RGB model now default for filtering
- Keybindings changed for inspect_images.py
- New DJI Mini 2 parameters from Metashape


SSIMS_v0.3.1.4 ----------------------------------------------------------------

Minor changes:
Expand Down
4 changes: 2 additions & 2 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

__package_name__ = 'SSIMS: Preprocessing tool for UAV image velocimetry'
__description__ = 'Preprocessing and video stabilization tool for UAS/UAV image velocimetry based on Structural Similarity (SSIM) Index metric'
__version__ = '0.3.1.4'
__version__ = '0.3.2.0'
__status__ = 'beta'
__date_deployed__ = '2022-03-11'
__date_deployed__ = '2022-04-05'

__author__ = 'Robert Ljubicic, University of Belgrade - Civil Engineering Faculty'
__author_email__ = '[email protected]'
Expand Down
258 changes: 258 additions & 0 deletions scripts/colorspaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this package. If not, you can get eh GNU GPL from
https://www.gnu.org/licenses/gpl-3.0.en.html.
Created by Robert Ljubicic.
"""

try:
from __init__ import *
from matplotlib.widgets import Slider
from sys import exit

import glob
import matplotlib.pyplot as plt

except Exception as ex:
print('\n[EXCEPTION] Import failed: \n\n'
' {}'.format(ex))
input('\nPress ENTER/RETURN to exit...')
exit()


def snr(a):
m = np.mean(a)
sd = np.std(a)
return m/sd


def update_frame(val):
global current_frame

current_frame = frames_list[sl_ax_frame_num.val]
get_colospaces(current_frame, xlim, ylim)

plt.draw()


def keypress(event):
if event.key == 'escape':
exit()

elif event.key == 'down':
if sl_ax_frame_num.val == 0:
sl_ax_frame_num.set_val(num_frames - 1)
else:
sl_ax_frame_num.set_val(sl_ax_frame_num.val - 1)

elif event.key == 'up':
if sl_ax_frame_num.val == num_frames - 1:
sl_ax_frame_num.set_val(0)
else:
sl_ax_frame_num.set_val(sl_ax_frame_num.val + 1)

elif event.key == 'pageup':
if sl_ax_frame_num.val >= num_frames - 10:
sl_ax_frame_num.set_val(0)
else:
sl_ax_frame_num.set_val(sl_ax_frame_num.val + 10)

elif event.key == 'pagedown':
if sl_ax_frame_num.val <= 9:
sl_ax_frame_num.set_val(num_frames - 1)
else:
sl_ax_frame_num.set_val(sl_ax_frame_num.val - 10)

update_frame(sl_ax_frame_num.val)


def get_colospaces(path, xlim, ylim):
img_bgr = cv2.imread(path)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
img_hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)
img_lab = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2LAB)

cs_list = [
img_rgb,
img_rgb[:, :, 0],
img_rgb[:, :, 1],
img_rgb[:, :, 2],
img_gray,
img_hsv[:, :, 0],
img_hsv[:, :, 1],
img_hsv[:, :, 2],
None,
img_lab[:, :, 0],
img_lab[:, :, 1],
img_lab[:, :, 2],
]

for i in range(len(cs_list)):
if cs_list[i] is not None:
img = cs_list[i]
imshow_list[i].set_data(img)
ax_list[i].set_xlim(xlim)
ax_list[i].set_ylim(ylim)
ax_list[i].set_title(cs_names[i])

if i == 0:
ax_list[i].set_title(cs_names[i])
else:
ax_snr = snr(img[ylim[1]: ylim[0], xlim[0]: xlim[1]])
ax_list[i].set_title('{}, SNR={:.2f}'.format(cs_names[i], ax_snr))


def on_lims_change(event_ax):
global xlim
global ylim

cid_list = list(event_ax.callbacks.callbacks['ylim_changed'].keys())
for cid in cid_list:
event_ax.callbacks.disconnect(cid)

xlim = [int(x) for x in event_ax.get_xlim()]
ylim = [int(y) for y in event_ax.get_ylim()]

event_ax.set_xlim(xlim)
event_ax.set_ylim(ylim)

for i in range(1, len(cs_names)):
if cs_names[i] != '':
a = ax_list[i]
ax_title = a.get_title().split(', ')[0]
ax_img = np.array(a.get_images()[0]._A)
ax_img_crop = ax_img[ylim[1]: ylim[0], xlim[0]: xlim[1]]
ax_snr = snr(ax_img_crop)

a.set_title('{}, SNR={:.2f}'.format(ax_title, ax_snr))

event_ax.callbacks.connect('ylim_changed', on_lims_change)


if __name__ == '__main__':
try:
parser = ArgumentParser()
parser.add_argument('--folder', type=str, help='Path to image file or folder with images')
parser.add_argument('--ext', type=str, help='Path to image file')
args = parser.parse_args()

frames_list = glob.glob('{}/*.{}'.format(args.folder, args.ext))
num_frames = len(frames_list)
first_frame = cv2.imread(frames_list[0], 0)

h, w = first_frame.shape
xlim = [0, w]
ylim = [h, 0]

nrows, ncols = 3, 4
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, sharex=True, sharey=True)
plt.subplots_adjust(left=0.01, right=0.99, top=0.96, bottom=0.06, wspace=0.02, hspace=0.1)
fig.canvas.mpl_connect('key_press_event', keypress)

legend = 'Use O to zoom and P to pan images,\n' \
'Use slider to select frame,\n' \
'use UP and DOWN keys to move by +/- 1 frame\n' \
'or PageUP and PageDOWN keys to move by +/- 10 frames\n' \
'Press ESC or Q to exit'

legend_toggle = plt.text(0.5, 0.5, legend,
horizontalalignment='center',
verticalalignment='center',
transform=ax[2][0].transAxes,
bbox=dict(facecolor='white', alpha=0.5),
fontsize=9,
)

axcolor = 'lightgoldenrodyellow'
valfmt = "%d"

ax_frame_num = plt.axes([0.2, 0.02, 0.63, 0.03], facecolor=axcolor)
sl_ax_frame_num = Slider(ax_frame_num, 'Frame #\n({} total)'.format(num_frames), 0, num_frames - 1, valinit=0, valstep=1, valfmt=valfmt)
sl_ax_frame_num.on_changed(update_frame)

cs_names = [
'Original RGB',
'[R]GB',
'R[G]B',
'RG[B]',
'Grayscale',
'[H]SV',
'H[S]V',
'HS[V]',
'',
'[L*]a*b*',
'L*[a*]b*',
'L*a*[b*]',
]

ax_list = ax.reshape(-1)
imshow_list = [None] * 12

current_frame = frames_list[0]

img_bgr = cv2.imread(current_frame)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
img_hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)
img_lab = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2LAB)

cs_list = [
img_rgb,
img_rgb[:, :, 0],
img_rgb[:, :, 1],
img_rgb[:, :, 2],
img_gray,
img_hsv[:, :, 0],
img_hsv[:, :, 1],
img_hsv[:, :, 2],
None,
img_lab[:, :, 0],
img_lab[:, :, 1],
img_lab[:, :, 2],
]

for i in range(len(cs_list)):
if cs_list[i] is not None:
img = cs_list[i]
imshow_list[i] = ax_list[i].imshow(img)
ax_list[i].set_xlim(xlim)
ax_list[i].set_ylim(ylim)
ax_list[i].set_title(cs_names[i])

if i == 0:
ax_list[i].set_title(cs_names[i])
else:
ax_snr = snr(img[ylim[1]: ylim[0], xlim[0]: xlim[1]])
ax_list[i].set_title('{}, SNR={:.2f}'.format(cs_names[i], ax_snr))

[a.set_axis_off() for a in ax_list]
[a.callbacks.connect('ylim_changed', on_lims_change) for a in ax_list]

try:
mng = plt.get_current_fig_manager()
mng.window.state('zoomed')
mng.set_window_title('Inspect frames')
except:
pass

plt.show()

except Exception as ex:
print('\n[EXCEPTION] The following exception has occurred: \n\n'
' {}'.format(ex))
input('\nPress ENTER/RETURN to exit...')
Loading

0 comments on commit 5455971

Please sign in to comment.