diff --git a/.ipynb_checkpoints/movie_writer-checkpoint.ipynb b/.ipynb_checkpoints/movie_writer-checkpoint.ipynb new file mode 100755 index 0000000000000000000000000000000000000000..ffd5cf3592da95abceb2ac83326bddc2882c1a6c --- /dev/null +++ b/.ipynb_checkpoints/movie_writer-checkpoint.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import imageio\n", + "import os\n", + "import cv2\n", + "from datetime import datetime\n", + "from tqdm import tqdm_notebook as tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "in_dir = r'C:\\Users\\Wheeler\\Desktop\\LCL_software\\Experiments\\experiment_18_07_2018___12.20.17.722253'\n", + "out_loc = r'C:\\Users\\Wheeler\\Desktop\\LCL_software\\Experiments\\experiment_18_07_2018___12.20.17.avi'\n", + "images = []\n", + "clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\n", + "files = [os.path.join(in_dir, f) for f in os.listdir(in_dir) if '.tif' in f] \n", + "\n", + "\n", + "def get_time(file_name):\n", + "# t = file_name.split('_')[-2].split('_')[0]\n", + " t=file_name.split('_')[-1].split('.tif')[0]\n", + " t = datetime.strptime(t, '%H.%M.%S.%f')\n", + " t = t.hour*3600 + t.minute*60 + t.second + t.microsecond/10**6\n", + " return t\n", + " \n", + "\n", + "files.sort(key=get_time,reverse = False)\n", + "# for file in files:\n", + "# print('processing...',file.split('/')[-1])\n", + "# img = cv2.imread(file,0)\n", + "# img = cv2.resize(img,(int(img.shape[1]/3),int(img.shape[0]/3)),interpolation = cv2.INTER_CUBIC)\n", + "# img = clahe.apply(img)\n", + "# images.append(img)\n", + "# images = [images[0]] * 2 + images\n", + "# imageio.mimsave(out_loc, images,duration=.2)\n", + "# print('done')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(822, 1024, 3)\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a9c244c465bc40b8bc8e603e2ef92fb0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "A Jupyter Widget" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "done\n" + ] + } + ], + "source": [ + "img = cv2.imread(files[0],1)\n", + "width = img.shape[1]\n", + "height = img.shape[0]\n", + "print(img.shape)\n", + "use_clahe = False\n", + "fourcc = cv2.VideoWriter_fourcc(*'MJPG') # Be sure to use lower case\n", + "out = cv2.VideoWriter(out_loc, fourcc, 14.0, (int(width/1), int(height/1)))\n", + "clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\n", + "for file in tqdm(files):\n", + " img = cv2.imread(file,1)\n", + " img = cv2.resize(img,(int(width/1),int(height/1)))\n", + " if use_clahe == True:\n", + " r,g,b = img[:,:,0],img[:,:,1],img[:,:,2]\n", + " r = clahe.apply(r)\n", + " g = clahe.apply(g)\n", + " b = clahe.apply(b)\n", + " img[:,:,0] = r\n", + " img[:,:,1] = g\n", + " img[:,:,2] = b\n", + " out.write(img)\n", + "out.release()\n", + "print('done')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/__pycache__/localizer.cpython-36.pyc b/__pycache__/localizer.cpython-36.pyc index 984146bd28f5c34bc3b87411c54223841883672b..14f3529b29e51701748e8410b3fa0ba409fae41d 100755 Binary files a/__pycache__/localizer.cpython-36.pyc and b/__pycache__/localizer.cpython-36.pyc differ diff --git a/localizer.py b/localizer.py index c8e678e7663db470e00fef8670d7379cce12210c..ac578097e6d8263119b71235b0b6e115ef3bc9ad 100755 --- a/localizer.py +++ b/localizer.py @@ -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) diff --git a/movie_writer.ipynb b/movie_writer.ipynb new file mode 100755 index 0000000000000000000000000000000000000000..a4413561a15c2901e7540da1fe46e598397aa1c0 --- /dev/null +++ b/movie_writer.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import imageio\n", + "import os\n", + "import cv2\n", + "from datetime import datetime\n", + "from tqdm import tqdm_notebook as tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "in_dir = r'C:\\Users\\Wheeler\\Desktop\\LCL_software\\Experiments\\experiment_20_09_2018___10.08.42.888353'\n", + "out_loc = r'C:\\Users\\Wheeler\\Desktop\\LCL_software\\Experiments\\experiment_20_09_2018___10.08.42.avi'\n", + "images = []\n", + "clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\n", + "files = [os.path.join(in_dir, f) for f in os.listdir(in_dir) if '.tif' in f] \n", + "\n", + "\n", + "def get_time(file_name):\n", + "# t = file_name.split('_')[-2].split('_')[0]\n", + " t=file_name.split('_')[-1].split('.tif')[0]\n", + " t = datetime.strptime(t, '%H.%M.%S.%f')\n", + " t = t.hour*3600 + t.minute*60 + t.second + t.microsecond/10**6\n", + " return t\n", + " \n", + "\n", + "files.sort(key=get_time,reverse = False)\n", + "# for file in files:\n", + "# print('processing...',file.split('/')[-1])\n", + "# img = cv2.imread(file,0)\n", + "# img = cv2.resize(img,(int(img.shape[1]/3),int(img.shape[0]/3)),interpolation = cv2.INTER_CUBIC)\n", + "# img = clahe.apply(img)\n", + "# images.append(img)\n", + "# images = [images[0]] * 2 + images\n", + "# imageio.mimsave(out_loc, images,duration=.2)\n", + "# print('done')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(822, 1024, 3)\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "09d2a745ee4b4b68bd1b8fe19bdc89be", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "A Jupyter Widget" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "done\n" + ] + } + ], + "source": [ + "img = cv2.imread(files[0],1)\n", + "width = img.shape[1]\n", + "height = img.shape[0]\n", + "print(img.shape)\n", + "use_clahe = False\n", + "fourcc = cv2.VideoWriter_fourcc(*'MJPG') # Be sure to use lower case\n", + "out = cv2.VideoWriter(out_loc, fourcc, 14.0, (int(width/1), int(height/1)))\n", + "clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\n", + "for file in tqdm(files):\n", + " img = cv2.imread(file,1)\n", + " img = cv2.resize(img,(int(width/1),int(height/1)))\n", + " if use_clahe == True:\n", + " r,g,b = img[:,:,0],img[:,:,1],img[:,:,2]\n", + " r = clahe.apply(r)\n", + " g = clahe.apply(g)\n", + " b = clahe.apply(b)\n", + " img[:,:,0] = r\n", + " img[:,:,1] = g\n", + " img[:,:,2] = b\n", + " out.write(img)\n", + "out.release()\n", + "print('done')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/zoom_gui_test.py b/zoom_gui_test.py new file mode 100755 index 0000000000000000000000000000000000000000..17488a5e2cff63278f252e9a057153cd9486ff74 --- /dev/null +++ b/zoom_gui_test.py @@ -0,0 +1,53 @@ +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() + + + +