Skip to content
Snippets Groups Projects
Commit f3666313 authored by Unknown's avatar Unknown
Browse files

added tiling zoom proto

parent efab24b3
Branches
No related merge requests found
%% Cell type:code id: tags:
``` python
import imageio
import os
import cv2
from datetime import datetime
from tqdm import tqdm_notebook as tqdm
```
%% Cell type:code id: tags:
``` python
in_dir = r'C:\Users\Wheeler\Desktop\LCL_software\Experiments\experiment_18_07_2018___12.20.17.722253'
out_loc = r'C:\Users\Wheeler\Desktop\LCL_software\Experiments\experiment_18_07_2018___12.20.17.avi'
images = []
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
files = [os.path.join(in_dir, f) for f in os.listdir(in_dir) if '.tif' in f]
def get_time(file_name):
# t = file_name.split('_')[-2].split('_')[0]
t=file_name.split('_')[-1].split('.tif')[0]
t = datetime.strptime(t, '%H.%M.%S.%f')
t = t.hour*3600 + t.minute*60 + t.second + t.microsecond/10**6
return t
files.sort(key=get_time,reverse = False)
# for file in files:
# print('processing...',file.split('/')[-1])
# img = cv2.imread(file,0)
# img = cv2.resize(img,(int(img.shape[1]/3),int(img.shape[0]/3)),interpolation = cv2.INTER_CUBIC)
# img = clahe.apply(img)
# images.append(img)
# images = [images[0]] * 2 + images
# imageio.mimsave(out_loc, images,duration=.2)
# print('done')
```
%% Cell type:code id: tags:
``` python
img = cv2.imread(files[0],1)
width = img.shape[1]
height = img.shape[0]
print(img.shape)
use_clahe = False
fourcc = cv2.VideoWriter_fourcc(*'MJPG') # Be sure to use lower case
out = cv2.VideoWriter(out_loc, fourcc, 14.0, (int(width/1), int(height/1)))
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
for file in tqdm(files):
img = cv2.imread(file,1)
img = cv2.resize(img,(int(width/1),int(height/1)))
if use_clahe == True:
r,g,b = img[:,:,0],img[:,:,1],img[:,:,2]
r = clahe.apply(r)
g = clahe.apply(g)
b = clahe.apply(b)
img[:,:,0] = r
img[:,:,1] = g
img[:,:,2] = b
out.write(img)
out.release()
print('done')
```
%% Output
(822, 1024, 3)
done
%% Cell type:code id: tags:
``` python
```
No preview for this file type
......@@ -30,15 +30,16 @@ class wellStitcher():
self.curr_y = self.center
# initialize the image and show it
self.img_x,self.img_y = int(1024),int(822)
self.well_img = np.zeros((self.img_y*self.box_size,self.img_x*self.box_size,3))
self.well_img = np.zeros((self.img_y*self.box_size,self.img_x*self.box_size,3))
self.stitch_img(initial_img)
def manage_zoom(self,pos):
print('trackbar at',pos)
def stitch_img(self,img):
self.well_img[self.curr_y*self.img_y:(self.curr_y+1)*self.img_y, self.curr_x*self.img_x:(self.curr_x+1)*self.img_x,:] = img
self.resized_img = cv2.resize(self.well_img,(1024,822))
cv2.imshow('Stitch',self.resized_img)
self.resized_img = cv2.resize(self.well_img,(int(1024*.8),int(822*.8)),interpolation = cv2.INTER_AREA)
cv2.imshow('Stitch',self.resized_img)
def add_img(self,let,img):
if let == 'u': self.curr_y -= 1
......@@ -52,7 +53,7 @@ class wellStitcher():
experiment_folder_location = os.path.join(os.path.dirname(os.path.abspath(__file__)),'well_images')
cv2.imwrite(os.path.join(experiment_folder_location,
'{}___{}.tif'.format('well_image',now())),self.well_img)
cv2.createTrackbar('Zoom (2^x)','Stitch',1,6,self.manage_zoom)
class Localizer(QtCore.QObject):
localizer_move_signal = QtCore.pyqtSignal('PyQt_PyObject','PyQt_PyObject','PyQt_PyObject','PyQt_PyObject')
......@@ -168,7 +169,8 @@ class Localizer(QtCore.QObject):
self.localizer_move_signal.emit(position,False,False,False)
@QtCore.pyqtSlot()
def tile_well(self):
def localize2(self):
box_size = 5
self.well_center = self.get_stage_position()
stitcher = wellStitcher(box_size,self.image)
directions = self.get_spiral_directions(box_size)
......@@ -194,9 +196,9 @@ class Localizer(QtCore.QObject):
self.auto_lysis = True
self.well_center = self.get_stage_position()
# now start moving and lysing all in view
self.lyse_all_in_view()
# self.lyse_all_in_view()
box_size = 5
# stitcher = wellStitcher(box_size,self.image)
stitcher = wellStitcher(box_size,self.image)
directions = self.get_spiral_directions(box_size)
self.get_well_center = False
for num,let in directions:
......@@ -214,10 +216,10 @@ class Localizer(QtCore.QObject):
QApplication.processEvents()
self.delay()
QApplication.processEvents()
# stitcher.add_img(let,self.image)
self.lyse_all_in_view()
stitcher.add_img(let,self.image)
# self.lyse_all_in_view()
comment('lysis completed!')
# stitcher.write_well_img()
stitcher.write_well_img()
# self.return_to_original_position(self.well_center)
......
%% Cell type:code id: tags:
``` python
import imageio
import os
import cv2
from datetime import datetime
from tqdm import tqdm_notebook as tqdm
```
%% Cell type:code id: tags:
``` python
in_dir = r'C:\Users\Wheeler\Desktop\LCL_software\Experiments\experiment_20_09_2018___10.08.42.888353'
out_loc = r'C:\Users\Wheeler\Desktop\LCL_software\Experiments\experiment_20_09_2018___10.08.42.avi'
images = []
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
files = [os.path.join(in_dir, f) for f in os.listdir(in_dir) if '.tif' in f]
def get_time(file_name):
# t = file_name.split('_')[-2].split('_')[0]
t=file_name.split('_')[-1].split('.tif')[0]
t = datetime.strptime(t, '%H.%M.%S.%f')
t = t.hour*3600 + t.minute*60 + t.second + t.microsecond/10**6
return t
files.sort(key=get_time,reverse = False)
# for file in files:
# print('processing...',file.split('/')[-1])
# img = cv2.imread(file,0)
# img = cv2.resize(img,(int(img.shape[1]/3),int(img.shape[0]/3)),interpolation = cv2.INTER_CUBIC)
# img = clahe.apply(img)
# images.append(img)
# images = [images[0]] * 2 + images
# imageio.mimsave(out_loc, images,duration=.2)
# print('done')
```
%% Cell type:code id: tags:
``` python
img = cv2.imread(files[0],1)
width = img.shape[1]
height = img.shape[0]
print(img.shape)
use_clahe = False
fourcc = cv2.VideoWriter_fourcc(*'MJPG') # Be sure to use lower case
out = cv2.VideoWriter(out_loc, fourcc, 14.0, (int(width/1), int(height/1)))
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
for file in tqdm(files):
img = cv2.imread(file,1)
img = cv2.resize(img,(int(width/1),int(height/1)))
if use_clahe == True:
r,g,b = img[:,:,0],img[:,:,1],img[:,:,2]
r = clahe.apply(r)
g = clahe.apply(g)
b = clahe.apply(b)
img[:,:,0] = r
img[:,:,1] = g
img[:,:,2] = b
out.write(img)
out.release()
print('done')
```
%% Output
(822, 1024, 3)
done
%% Cell type:code id: tags:
``` python
```
import numpy
import cv2
img_loc = r'C:\Users\Wheeler\Desktop\LCL_software\well_images\well_image___20_09_2018___12.18.52.033870.tif'
class Stitcher():
def __init__(self):
self.img = cv2.imread(img_loc)
# the values we will use to resize the image at the end to fit the screen
self.user_view_x = int(1024*.78)
self.user_view_y = int(822*.78)
# the center point of our image (will be updated when we move along the image)
self.x = int(self.img.shape[0]/2)
self.y = int(self.img.shape[1]/2)
# the number of pixels the unaltered image has (will be updated with zoom)
self.px_x = int(self.img.shape[0])
self.px_y = int(self.img.shape[1])
self.img_resized = cv2.resize(self.img,(self.user_view_x,self.user_view_y),cv2.INTER_AREA)
cv2.imshow('Stitch',self.img_resized)
cv2.createTrackbar('Zoom','Stitch',0,6,self.manage_zoom)
cv2.waitKey(0)
cv2.destroyAllWindows()
def zoom(self,amt):
if amt != 0:
self.px_x = int(self.px_x/amt)
self.px_y = int(self.px_y/amt)
# now we need to update based on our location and the new unaltered img
# values
cropped_img = self.img[self.x:self.px_x,self.y:self.px_y]
img_resized = cv2.resize(cropped_img,
(self.user_view_x,self.user_view_y),
cv2.INTER_AREA)
cv2.imshow('Stitch',img_resized)
def manage_zoom(self,pos):
print('trackbar at',pos)
self.zoom(pos)
s = Stitcher()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment