-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77a9e3e
commit 7f3cf06
Showing
290 changed files
with
41,871 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c0cecda1-8604-44a4-9b9c-8e8bade04950", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "", | ||
"name": "" | ||
}, | ||
"language_info": { | ||
"name": "" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
from datetime import datetime | ||
import threading | ||
from tkinter import * | ||
from tkinter import Button | ||
from simba.utils.enums import Keys, Links, Options | ||
from simba.mixins.pop_up_mixin import PopUpMixin | ||
from simba.ui.tkinter_functions import CreateLabelFrameWithIcon, FileSelect, FolderSelect | ||
from simba.utils.checks import check_file_exist_and_readable, check_if_dir_exists | ||
from simba.video_processors.clahe_ui import interactive_clahe_ui | ||
from simba.video_processors.video_processing import clahe_enhance_video | ||
from simba.utils.read_write import find_files_of_filetypes_in_directory, get_fn_ext | ||
from simba.utils.printing import stdout_success, SimbaTimer | ||
|
||
class CLAHEPopUp(PopUpMixin): | ||
def __init__(self): | ||
super().__init__(title="CLAHE VIDEO CONVERSION") | ||
single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SINGLE VIDEO - Contrast Limited Adaptive Histogram Equalization", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value) | ||
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)]) | ||
run_single_video_btn = Button(single_video_frm, text="Apply CLAHE", command=lambda: self.run_single_video()) | ||
|
||
multiple_videos_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="MULTIPLE VIDEOs - Contrast Limited Adaptive Histogram Equalization", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value) | ||
self.selected_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", lblwidth=25) | ||
run_multiple_btn = Button(multiple_videos_frm, text="RUN VIDEO DIRECTORY", command=lambda: self.run_directory(), fg="blue") | ||
|
||
single_video_frm.grid(row=0, column=0, sticky=NW) | ||
self.selected_video.grid(row=0, column=0, sticky=NW) | ||
run_single_video_btn.grid(row=1, column=0, sticky=NW) | ||
|
||
multiple_videos_frm.grid(row=1, column=0, sticky=NW) | ||
self.selected_dir.grid(row=0, column=0, sticky=NW) | ||
run_multiple_btn.grid(row=1, column=0, sticky=NW) | ||
|
||
def run_single_video(self): | ||
selected_video = self.selected_video.file_path | ||
check_file_exist_and_readable(file_path=selected_video) | ||
threading.Thread(target=clahe_enhance_video(file_path=selected_video)).start() | ||
|
||
def run_directory(self): | ||
timer = SimbaTimer(start=True) | ||
video_dir = self.selected_dir.folder_path | ||
check_if_dir_exists(in_dir=video_dir, source=self.__class__.__name__) | ||
self.video_paths = find_files_of_filetypes_in_directory(directory=video_dir, extensions=Options.ALL_VIDEO_FORMAT_OPTIONS.value, raise_error=True) | ||
for file_path in self.video_paths: | ||
threading.Thread(target=clahe_enhance_video(file_path=file_path)).start() | ||
timer.stop_timer() | ||
stdout_success(msg=f'CLAHE enhanced {len(self.video_paths)} video(s)', elapsed_time=timer.elapsed_time_str) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# # Function to update CLAHE | ||
# def update_clahe(x): | ||
# global img, clahe | ||
# clip_limit = cv2.getTrackbarPos('Clip Limit', 'CLAHE') / 10.0 # Scale the trackbar value | ||
# tile_size = cv2.getTrackbarPos('Tile Size', 'CLAHE') | ||
# if tile_size % 2 == 0: | ||
# tile_size += 1 # Ensure tile size is odd | ||
# clahe = cv2.createCLAHE(clipLimit=clip_limit, tileGridSize=(tile_size, tile_size)) | ||
# img_clahe = clahe.apply(img) | ||
# cv2.imshow('CLAHE', img_clahe) | ||
# | ||
# # Load an image | ||
# img = cv2.imread('/Users/simon/Downloads/PXL_20240429_222923838.jpg', cv2.IMREAD_GRAYSCALE) | ||
# | ||
# # Create a window | ||
# cv2.namedWindow('CLAHE', cv2.WINDOW_NORMAL) | ||
# | ||
# # Initialize the clip limit trackbar | ||
# cv2.createTrackbar('Clip Limit', 'CLAHE', 10, 300, update_clahe) | ||
# | ||
# # Initialize the tile size trackbar | ||
# cv2.createTrackbar('Tile Size', 'CLAHE', 8, 64, update_clahe) | ||
# | ||
# # Apply CLAHE with initial parameters | ||
# clahe = cv2.createCLAHE(clipLimit=1.0, tileGridSize=(8, 8)) | ||
# img_clahe = clahe.apply(img) | ||
# cv2.imshow('Original', img) | ||
# cv2.imshow('CLAHE', img_clahe) | ||
# | ||
# cv2.waitKey(0) | ||
# cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import os | ||
import numpy as np | ||
|
||
from simba.mixins.config_reader import ConfigReader | ||
from simba.mixins.geometry_mixin import GeometryMixin | ||
from simba.mixins.image_mixin import ImageMixin | ||
from simba.utils.read_write import read_df | ||
from simba.plotting.geometry_plotter import GeometryPlotter | ||
|
||
CONFIG_PATH = '/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/project_config.ini' | ||
VIDEO_NAME = '2022-06-20_NOB_DOT_4' | ||
|
||
cfg = ConfigReader(config_path=CONFIG_PATH, read_video_info=False) | ||
data = read_df(os.path.join(cfg.outlier_corrected_dir, VIDEO_NAME + f'.{cfg.file_type}'), file_type=cfg.file_type) | ||
video_path = os.path.join(cfg.video_dir, VIDEO_NAME + '.mp4') | ||
animal_df = data[[x for x in data.columns if x in cfg.animal_bp_dict['Animal_1']['X_bps'] + cfg.animal_bp_dict['Animal_1']['Y_bps']]] | ||
animal_data = animal_df.drop(['Tail_end_x', 'Tail_end_y'], axis=1).values.reshape(-1, 7, 2).astype(np.int) | ||
|
||
animal_polygons = GeometryMixin.bodyparts_to_polygon(data=animal_data)[:300] | ||
geometry_plotter = GeometryPlotter(config_path=CONFIG_PATH, | ||
geometries=[animal_polygons], | ||
video_name=VIDEO_NAME, | ||
thickness=10, | ||
bg_opacity=0.2) | ||
geometry_plotter.run() | ||
|
||
# | ||
# animal_rectangles = GeometryMixin().multiframe_minimum_rotated_rectangle(shapes=animal_polygons) | ||
# geometry_plotter = GeometryPlotter(config_path=CONFIG_PATH, | ||
# geometries=[animal_rectangles], | ||
# video_name=VIDEO_NAME, | ||
# thickness=10) | ||
# geometry_plotter.run() | ||
# | ||
# animal_polygons_buffered = GeometryMixin.bodyparts_to_polygon(data=animal_data[:300], parallel_offset=100, pixels_per_mm=1.88) | ||
# geometry_plotter = GeometryPlotter(config_path=CONFIG_PATH, | ||
# geometries=[animal_polygons], | ||
# video_name=VIDEO_NAME, | ||
# thickness=10, | ||
# bg_opacity=1.0) | ||
# geometry_plotter.run() | ||
|
||
imgs = ImageMixin().read_img_batch_from_video(video_path=video_path, start_frm=0, end_frm=299) | ||
imgs = np.stack(list(imgs.values())) | ||
# animal_polygons_buffered = np.array(animal_polygons_buffered).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=animal_polygons_buffered) | ||
|
||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
# animal_polygons_tighter = np.array(animal_polygons).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=animal_polygons_tighter) | ||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced_tighter.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
animal_head = animal_df[['Nose_x', 'Nose_y', 'Ear_left_x', 'Ear_left_y', 'Ear_right_x', 'Ear_right_y']].values.reshape(-1, 3, 2).astype(np.int) | ||
#animal_head_polygons = GeometryMixin.bodyparts_to_polygon(data=animal_head, parallel_offset=100, pixels_per_mm=1.88)[:300] | ||
# animal_head_polygons = np.array(animal_head_polygons).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=animal_head_polygons) | ||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced_head.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
# animal_head_polygons = GeometryMixin.bodyparts_to_polygon(data=animal_head, parallel_offset=25, pixels_per_mm=1.88)[:300] | ||
# animal_head_polygons = np.array(animal_head_polygons).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=animal_head_polygons) | ||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced_head_tighter_even.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
|
||
|
||
# animal_head_polygons = GeometryMixin.bodyparts_to_polygon(data=animal_head)[:300] | ||
# head_centers = GeometryMixin.get_center(shape=animal_head_polygons) | ||
# head_circles = GeometryMixin.bodyparts_to_circle(data=head_centers, parallel_offset=100, pixels_per_mm=1.88) | ||
# head_circles = np.array(head_circles).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=head_circles) | ||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced_head_circles.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
|
||
# head_circles = GeometryMixin.bodyparts_to_circle(data=head_centers, parallel_offset=50, pixels_per_mm=1.88) | ||
# head_circles = np.array(head_circles).T.reshape(-1, 1) | ||
# sliced_images = ImageMixin().slice_shapes_in_imgs(imgs=imgs, shapes=head_circles) | ||
# ImageMixin.img_stack_to_video(imgs=sliced_images, | ||
# save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/sliced_head_circles_tighter.mp4', | ||
# fps=30, | ||
# verbose=True) | ||
|
||
|
||
#video_bg_substraction_mp(video_path=video_path, save_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/frames/output/geometry_visualization/bg_removed.mp4') |
Oops, something went wrong.