예제 #1
0
def get_free_memory():
    """gets the free memory thats available to ImageJ

    Returns
    -------
    free_memory : integer
        the free memory in bytes
    """
    max_memory = int(IJ.maxMemory())
    used_memory = int(IJ.currentMemory())
    free_memory = max_memory - used_memory

    return free_memory
예제 #2
0
def get_image(info, default_path, used_files):
	"""handle getting image from file"""
	check_for_file_overlap_OK = False;
	while not check_for_file_overlap_OK:
		info.set_input_file_path(file_location_chooser(default_path));
		if info.get_input_file_path() in used_files:
			dlg = GenericDialog("Image already used...");
			dlg.addMessage("This image has already been used in this analysis run.  \n " + 
					"Continue with this image, or choose a new one?");
			dlg.setOKLabel("Continue");
			dlg.setCancelLabel("Choose again...");
			dlg.showDialog();
			check_for_file_overlap_OK = False if dlg.wasCanceled() else True;
		else:
			check_for_file_overlap_OK = True;
	import_opts, info = choose_series(info.get_input_file_path(), info)

	imps = bf.openImagePlus(import_opts);
	imp = imps[0];
	
	try:
		memory_usage = IJ.currentMemory()/IJ.maxMemory();
		print("memory usage = " +str(memory_usage));
		# arbitrary limit...
		if memory_usage > 0.95: 
			IJ.run(imp, "8-bit", "");
			print("WARNING - IMAGE CONVERTED TO 8 BIT TO CONSERVE MEMORY!");
		info.set_metadata_file_path(os.path.splitext(info.get_input_file_path())[0] + ".txt");
		metadata = import_iq3_metadata(info.get_metadata_file_path());
		IJ.run(imp, "Properties...", "channels=" + str(int(metadata['n_channels'])) + 
										" slices=" + str(int(metadata['z_pixels'])) + 
										" frames=1 unit=" + str(metadata['x_unit']) + 
										" pixel_width=" + str(metadata['x_physical_size']) + 
										" pixel_height=" + str(metadata['y_physical_size']) + 
										" voxel_depth=" + str(metadata['z_extent']/metadata['z_pixels']));
		info.set_xy_pixel_size_um(metadata['x_physical_size']);
		info.set_z_plane_spacing_um(metadata['z_extent']/metadata['z_pixels']);
		info = parse_info_from_filename(info);
	except e as Exception:
		print(e.message);
	finally:
		if imp is not None:
			imp.close();
	return imp, info;