def open(self, filename): """Open the video file and attach it to the class. Takes: filename - the full path to the video Gives: isOpened - True if opened, False otherwise """ if filename is not None: self.filename = filename ext = filename.split('.')[-1] if ext in ['tiff', 'tif', 'TIF', 'TIFF']: # For tiffs use tiffcapture self.format = 'TIFF' self.video = tc.opentiff(filename) self._is_open = True self.length = self.video.length self.shape = self.video.shape self._curr = 0 else: # For other formats try opencv self.format = 'CV' self.video = cv2.VideoCapture(filename) self._is_open = True self.length = self.video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) self.shape = ( int(self.video.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)), int(self.video.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))) self._curr = 0 return self.isOpened()
def __init__(self, video_source=0): # Open the video source self.vid = tc.opentiff(video_source) if not self.vid.isOpened(): raise ValueError("Unable to open video source", video_source) self.vid_copy = cv2.VideoCapture(video_source) self.end = False # Get video source width and height self.width = self.vid_copy.get(cv2.CAP_PROP_FRAME_WIDTH) self.height = self.vid_copy.get(cv2.CAP_PROP_FRAME_HEIGHT) self.frame_counter = 0 self.num_frames = 0
def loadImageStackFromFile(self, fileName=''): """ Load an image stack from file. Without any arguments, loadImageStackFromFile() will popup a file dialog to choose the image file. With a fileName argument, loadImageStackFromFile(fileName) will attempt to load the specified file directly. """ if len(fileName) == 0: if QT_VERSION_STR[0] == '4': fileName = QFileDialog.getOpenFileName(self, "Open TIFF stack file.") elif QT_VERSION_STR[0] == '5': fileName, dummy = QFileDialog.getOpenFileName(self, "Open TIFF stack file.") fileName = str(fileName) if len(fileName) and os.path.isfile(fileName): self._tiffCaptureHandle = tiffcapture.opentiff(fileName) self.showFrame(0)
def loadImageStackFromFile(self, fileName=''): """ Load an image stack from file. Without any arguments, loadImageStackFromFile() will popup a file dialog to choose the image file. With a fileName argument, loadImageStackFromFile(fileName) will attempt to load the specified file directly. """ if len(fileName) == 0: if QT_VERSION_STR[0] == '4': fileName = QFileDialog.getOpenFileName( self, "Open TIFF stack file.") elif QT_VERSION_STR[0] == '5': fileName, dummy = QFileDialog.getOpenFileName( self, "Open TIFF stack file.") fileName = str(fileName) if len(fileName) and os.path.isfile(fileName): self._tiffCaptureHandle = tiffcapture.opentiff(fileName) self.showFrame(0)
def filePacker(filePath,versionId, patientId, testId, frameWidth, frameHeight, frameNumber, decayPoint, heatingPoint,outFile): dateTimeObj = datetime.now() now = dateTimeObj.strftime("%d%m%Y%H%M%S")#ddMMyyyyHHmmss dateX = now.encode(encoding = 'ascii',errors='strict') tiff = tc.opentiff(filePath) #open img outputFile = open(outFile,"wb") outputFile.write(struct.pack('B',versionId)) outputFile.write(struct.pack('i',patientId)) outputFile.write(struct.pack('i',testId)) outputFile.write(struct.pack('14B',*dateX)) outputFile.write(struct.pack('i',frameWidth)) outputFile.write(struct.pack('i',frameHeight)) outputFile.write(struct.pack('i',frameNumber)) outputFile.write(struct.pack('i',decayPoint)) outputFile.write(struct.pack('i',heatingPoint)) frameLooper(tiff,outputFile,frameWidth,frameHeight) outputFile.close()
def main(): print(sys.argv[1]) tiff = tc.opentiff(sys.argv[1]) print(sys.getsizeof(open(sys.argv[1]))) i = 0 for img in tiff: if i ==30: print(sys.getsizeof(img)) img_arr = np.array(img, dtype='int64') print(img_arr[103,110]) img_arr = img_arr - 27315 print(img_arr[103, 110]) dt = np.dtype('int16') img_arr = np.array(img, dtype=dt) print(img_arr[103, 110]) img_arr= img_arr - 27315 print(img_arr[103, 110]) i += 1
def __init__(self, path, debug, output_name, windows_sizes = {}): self.filename = path.split('/')[-1] self.debug = debug self.output_name = output_name self.current_frame = 0 # just temporary self.big_contour = [] self.centers = [] #check if tiff if self.filename.split('.')[-1].lower() == 'tif': self.tiff = tc.opentiff(path) _,temp_img = self.tiff.retrieve() temp_img = np.array(temp_img, dtype=np.uint8) self.images.append(temp_img) for temp_img in self.tiff: self.images.append(np.array(temp_img, dtype=np.uint8)) self.img = np.array(self.images[0], dtype=np.uint8) self.images = [] self.all_frames = len(self.images) else: self.img_color = cv2.imread(path) self.img = self.img_color self.thresh = self.img self.org_img = self.img.copy() self.img_w, self.img_h = self.img.shape[:2] #TODO: check self.windows_sizes = windows_sizes self.window = {"max_height": 0, "max_width": 0, "min_height": self.img.shape[:2][0], "min_width": self.img.shape[:2][1]}
import skimage as skimage import time RESIZE_FACTOR = 5 DISTANCE_PER_PIXEL = 646.35 #ap = argparse.ArgumentParser() #ap.add_argument("-i", "--tiff", required=True, help="path to input dataset of images") #args = vars(ap.parse_args()) file_names = ['28052019_angioE02.tif', '28052019_angioH04.tif'] for file_name in file_names: tiff = tc.opentiff('videos\\' + file_name) log_folder_name = 'analysis\\' + file_name + '_imagelog' if not os.path.exists(log_folder_name): os.mkdir(log_folder_name) with open('analysis\\' + file_name + '_result.csv', 'w') as csvfile: filewriter = csv.writer(csvfile, delimiter=';', lineterminator='\n') filewriter.writerow([ 'Frame', 'number_of_joints', 'number_of_meshes', 'total_meshes_area', 'average_meshes_area', 'number_of_segments', 'total_segments_length' ]) index = 0
#writes a TIFF video into a text file in row order. this works import tiffcapture as tc import cv2 from PIL import Image import numpy import PIL import matplotlib.pyplot as plt tiff = tc.opentiff("Lepton_Capture_2.tiff") #open img _, first_img = tiff.retrieve() cv2.namedWindow('video') imarray = numpy.array(0) inc = 0 for img in tiff: #tempimg = cv2.absdiff(first_img, img) # bkgnd sub plt.imshow(img) plt.show() tempimg = img imarray = numpy.array(tempimg) np_im = imarray new_im = Image.fromarray(np_im) new_im.save("numpy_altered_sample_" + str(inc) + ".png") f = open("guru99.txt", "w+") for i in range(0, imarray.shape[0]): for j in range(0, imarray.shape[1]): f.write(str(imarray[i, j]) + " ") f.write("\n") f.close()
#! /usr/bin/python3 import numpy as np import cv2 import tiffcapture as tc import matplotlib.pyplot as plt def normalize_thermals(img): cv2.normalize(img, img, 0, 2**16 - 1, cv2.NORM_MINMAX) return img tiff = tc.opentiff("lufthavn24feb/20200224_132038/20200224_132425_IR_A.tiff") vidObj = cv2.VideoCapture( "lufthavn24feb/20200224_132038/20200224_132425_VIS_A.mov") n_RGB_frames = int(vidObj.get(cv2.CAP_PROP_FRAME_COUNT)) n_thermal_frames = tiff.length ratio = n_RGB_frames / n_thermal_frames _, first_img = tiff.retrieve() scale_percent = 400 # percent of original size width = int(first_img.shape[1] * scale_percent / 100) height = int(first_img.shape[0] * scale_percent / 100) dim = (width, height) cv2.namedWindow('thermal_video') #cv2.namedWindow('RGB_video')
outpath = '{0}/{1}_{2}'.format(path, path.split('/')[-1], args.out) if not os.path.isdir(outpath): os.mkdir(outpath) ## iteration on the observation sites (labeled with s + number) nSite = 1 listfiles=listfiles_all_channel # process cy5 initial in order to get the positions of patterns,also the size of windows and its area size pos_all=[] areas_all=[] centers_all=[] pattern_arm_all=[] for i in xrange(len(listfiles)): patt = tc.opentiff(path+'/'+listfiles[i]) temp = patt.find_and_read(0) imObj = utilities.ExtractImage(temp, 6) img_adapteq = exposure.equalize_adapthist(imObj.smooth, clip_limit=0.03) img_adapteq /= (np.max(img_adapteq)/255.) hist,bins = np.histogram(img_adapteq,256,[0,256]) hist2=smooth(hist,40) histmax = argrelmax(hist2) ret, thresh=cv2.threshold(np.array(img_adapteq, dtype = np.uint8), (histmax[-1][-1]+255)/2, 255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) thresh[thresh == 0] = 1 thresh[thresh == 255] = 0 selem = disk(5) thresh = erosion(thresh, selem) label_image = label(thresh) rep = regionprops(label_image)
output_dir = 'data/processed/' visualize = True verbose = True ## CONFIGURATION ========== name = filename.split('/') name = name[len(name) - 1] name = name.split('.')[0] if not os.path.isdir(output_dir): os.mkdir(output_dir) output_dir_vid = output_dir + name + '/' if not os.path.isdir(output_dir_vid): os.mkdir(output_dir_vid) cap = tc.opentiff(filename) n_frames = cap.length ## process the first frame j = 1 if verbose: print('Processing frame: ' + str(j) + '/' + str(n_frames), end='\r') # Variable for color to draw optical flow track color = (0, 255, 0) # retrieve first frame ret, first_frame = cap.read() # Converts frame to grayscale prev_gray = first_frame