beadpos_xcol = np.empty(MAX_BEADS_PERFRAME, dtype=np.uint16) beadpos_yrow = np.empty(MAX_BEADS_PERFRAME, dtype=np.uint16) segmask_image = np.empty(data_size, dtype=np.uint16) im = np.fromfile("09162009D_00_1000.raw", dtype=np.uint16) # the file format is a 6MB file on uint16s so # 1st 2MB is raw image # 2nd 2MB is flattened image # 3rd 2MB is binary object mask raw_image = im[0:1000000] binary_object_mask = im[2000000:3000000] print("The size is %d" % binary_object_mask.size) objects_found_old = np.where(binary_object_mask==1)[0].size print("Chao found %d objects" % objects_found_old) num_beads = FO.find_objects(1000, 1000, \ raw_image, \ beadpos_xcol, beadpos_yrow, \ segmask_image) print("I found %d objects" % num_beads) binary_object_mask = binary_object_mask*65535 segmask_image = segmask_image*65535 binary_object_mask = binary_object_mask.astype(np.uint8) segmask_image = segmask_image.astype(np.uint8) imChao = Image.fromarray(np.reshape(binary_object_mask, (1000, 1000) )) imNick = Image.fromarray(np.reshape(segmask_image, (1000, 1000) )) imChao.show(command="display") imNick.show(command="display") #imChao.show(command="eog") #imNick.show(command="eog")
def find(): """ This function: 1) Takes all images, saves with labels "_before" for all 2) Then finds all the objects of one color "mycolor", a) takes the images averaging over "frames" images a) finds all objects b) prints out a bunch of bead position values found in the image 3) creates an overlay image putting the "mycolor" object centroids on top of the raw images of the composite of all colors and saves a png of 'colorsnap-'+'find_overlay_' + my_color +'_before' + ".png """ # declare all globals for function global img_array global img_array_float global img_array_flat global beadpos_xcol global beadpos_yrow global segmask_image global exposures global gains global colors global frames global num_beads global my_color global my_color_ind global MapFunc global MaestroF num_beads = 0 MaestroF.darkfield_off() """ DO NOT Home the filter wheel!!! In between sequencing and releasing This destroys the mapping, since the filter whell cannot reapeatedly home To the same postion """ #MaestroF.filter_home() snapAllPics(exposures, gains, "_before") MaestroF.filter_goto(my_color) time.sleep(1) for i in range(frames): PC.py_snapPtr(img_array, \ exposures[my_color_ind], \ gains[my_color_ind] , \ my_color) img_array_float += img_array.astype(np.float) # end for img_array_out = (img_array_float/frames).astype(np.uint16) img_array_float *= 0 # reset accumulator #invert for images where beads are lighter than background IT.flatten_image(1000, 1000, img_array_out, img_array_flat,1) img_array_flat = 16383 - img_array_flat # invert the 14 bit image num_beads = FO.find_objects(1000, 1000, \ img_array_flat, \ beadpos_xcol, beadpos_yrow, \ segmask_image) print("The number of beads found: %d" % num_beads) MapFunc.convertPicPNG2(16383-img_array_flat,0,1) MapFunc.convertPicPNG2(segmask_image*65535, 0,2) print("phase ONE complete!!!!!!!!!!!!!") print("value at 1st point: %d at point %d, %d" % \ (img_array_out[beadpos_xcol[0]+1000*beadpos_yrow[0]], \ beadpos_xcol[0], beadpos_yrow[0])) print("value at 2nd point: %d at point %d, %d" % \ (img_array_out[beadpos_xcol[1]+1000*beadpos_yrow[1]], \ beadpos_xcol[1], beadpos_yrow[1])) print("value at 3rd point: %d at point %d, %d" % \ (img_array_out[beadpos_xcol[2]+1000*beadpos_yrow[2]], \ beadpos_xcol[2], beadpos_yrow[2])) #PC.cameraClose() # also frees up image buffer memory stop_release() """ imG = Image.open("map_0_1" +".png") # just beads imB = Image.open("map_0_2" +".png") # the found beads im = Image.new('RGB', (1000,1000)) pix = im.load() pixG = imG.load() pixB = imB.load() for i in range(1000): for j in range(1000): pix[i,j] = (0,pixG[i,j],pixB[i,j]) #px = -238501 # end for # end for im.save("color_overlay_orig" +".png", "png") """ """ saves the pretaken raw 14bit image as an 8 bit greyscale PNG by shifting out 6 bits """ shape = (1000, 1000) img_1D_list = [] for c in colors: img_file = open('colorsnap-'+c+'_before' +'.raw', 'rb') # load a 1000000 length array img_array_1D = np.fromfile(file=img_file, dtype=np.uint16) img_1D_list.append(img_array_1D.reshape(shape)) img_file.close() del img_array_1D # end for # R = cy5, G = cy3, B = txRed # yellow = fam ==> RGB:255,255,0 img_total = (img_1D_list[1] + \ img_1D_list[2] + \ img_1D_list[3]).clip(min=None,max=16383).astype(np.uint16) img_3D = np.dstack([img_total, \ 16383*segmask_image.reshape(shape), \ img_1D_list[my_color_ind]]) img_8bit = (img_3D >> 6).astype(np.uint8) #im = Image.fromarray(img_8bit.reshape(-1,1000*3),'RGB') im = Image.fromarray(img_8bit,'RGB') im.save('colorsnap-'+'find_overlay_' + my_color +'_before' + ".png", "png") # clean house del img_array_out del img_total del img_3D del img_8bit del im del shape del img_1D_list
segmask_image = np.empty(data_size, dtype=np.uint16) MaestroF.darkfield_off() MaestroF.filter_home() MaestroF.filter_goto(my_color) time.sleep(1) MapFunc.init_illum() MapFunc.light_all() PC.py_snapPtr(img_array, .35,80,my_color) #invert for images where beads are lighter than background img_array = 16383 - img_array # invert the 14 bit image num_beads = FO.find_objects(1000, 1000, \ img_array, \ beadpos_xcol, beadpos_yrow, \ segmask_image) print("The number of beads found: %d" % num_beads) MapFunc.convertPicPNG2(16383-img_array,0,1) MapFunc.convertPicPNG2(segmask_image*65535, 0,2) #MapFunc.convertPicPNG(segmask_image*65535+img_array, 0,3) print("phase ONE complete!!!!!!!!!!!!!") PC.cameraClose() # also frees up image buffer memory #MapFunc.illum_bitmap() MapFunc.illum_vector(beadpos_yrow,beadpos_xcol) time.sleep(1)