本文整理汇总了Python中jicbioimage.core.image.Image.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Image.from_file方法的具体用法?Python Image.from_file怎么用?Python Image.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jicbioimage.core.image.Image
的用法示例。
在下文中一共展示了Image.from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_manual_image_creation_from_file
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def test_manual_image_creation_from_file(self):
from jicbioimage.core.image import Image
# Preamble: let us define the path to a TIFF file and create a numpy
# array from it.
# from libtiff import TIFF
# tif = TIFF.open(path_to_tiff, 'r')
# ar = tif.read_image()
path_to_tiff = os.path.join(DATA_DIR, 'single-channel.ome.tif')
use_plugin('freeimage')
ar = imread(path_to_tiff)
# It is possible to create an image from a file.
image = Image.from_file(path_to_tiff)
self.assertEqual(len(image.history), 0)
self.assertEqual(image.history.creation,
'Created Image from {}'.format(path_to_tiff))
# With name...
image = Image.from_file(path_to_tiff, name='Test1')
self.assertEqual(image.history.creation,
'Created Image from {} as Test1'.format(path_to_tiff))
# Without history...
image = Image.from_file(path_to_tiff, log_in_history=False)
self.assertEqual(len(image.history), 0)
# It is worth noting the image can support more multiple channels.
# This is particularly important when reading in images in rgb format.
fpath = os.path.join(DATA_DIR, 'tjelvar.png')
image = Image.from_file(fpath)
self.assertEqual(image.shape, (50, 50, 3))
示例2: sample_image_from_lines
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def sample_image_from_lines(image_file, lines_file, dilation, reduce_method):
data_image = Image.from_file(image_file)
line_image = Image.from_file(lines_file)
segmented_lines = segment(line_image, dilation)
with open("all_series.csv", "w") as fh:
fh.write(csv_header())
for n, line_region in enumerate(yield_line_masks(segmented_lines)):
line_intensity = data_image * line_region
if reduce_method == "max":
line_profile = np.amax(line_intensity, axis=1)
elif reduce_method == "mean":
sum_intensity = np.sum(line_intensity, axis=1)
sum_rows = np.sum(line_region, axis=1)
line_profile = sum_intensity / sum_rows
else:
err_msg = "Unknown reduce method: {}".format(reduce_method)
raise(RuntimeError(err_msg))
series_filename = "series_{:02d}.csv".format(n)
save_line_profile(series_filename, line_profile, n)
fh.write(csv_body(line_profile, n))
示例3: test_scaling_of_written_files
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def test_scaling_of_written_files(self):
from jicbioimage.core.image import Image3D, Image
directory = os.path.join(TMP_DIR, "im3d")
z0 = np.zeros((50,50), dtype=np.uint8)
z1 = np.ones((50, 50), dtype=np.uint8)
stack = np.dstack([z0, z1])
im3d = Image3D.from_array(stack)
im3d.to_directory(directory)
im0 = Image.from_file(os.path.join(directory, "z0.png"))
im1 = Image.from_file(os.path.join(directory, "z1.png"))
self.assertTrue(np.array_equal(z0, im0))
self.assertTrue(np.array_equal(z1*255, im1))
z2 = np.ones((50, 50), dtype=np.uint8) * 255
stack = np.dstack([z0, z1, z2])
im3d = Image3D.from_array(stack)
im3d.to_directory(directory)
im0 = Image.from_file(os.path.join(directory, "z0.png"))
im1 = Image.from_file(os.path.join(directory, "z1.png"))
im2 = Image.from_file(os.path.join(directory, "z2.png"))
self.assertTrue(np.array_equal(z0, im0))
self.assertTrue(np.array_equal(z1, im1))
self.assertTrue(np.array_equal(z2*255, im1))
示例4: process_single_identifier
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def process_single_identifier(dataset, identifier, output_path):
print("Processing {}".format(identifier))
image = Image.from_file(dataset.abspath_from_identifier(identifier))
seeds = generate_seed_image(image, dataset, identifier)
segmentation = segment(image, seeds)
segmentation = filter_sides(segmentation)
segmentation = filter_touching_border(segmentation)
output_filename = generate_output_filename(
dataset,
identifier,
output_path,
'-segmented'
)
save_segmented_image_as_rgb(segmentation, output_filename)
false_colour_filename = generate_output_filename(
dataset,
identifier,
output_path,
'-false_colour'
)
with open(false_colour_filename, 'wb') as fh:
fh.write(segmentation.png())
示例5: find_kilobots
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def find_kilobots(image_filename, output_filename):
"""Find kilobots in a still image file."""
kilobot_image = Image.from_file(image_filename)
red_only = kilobot_image[:,:,0]
imsave('red.png', red_only)
edges = find_edges(red_only)
blurred = gaussian_filter(edges, sigma=2)
# bot_template = blurred[135:185,485:535]
# imsave('bot_template.png', bot_template)
bot_template = load_bot_template('bot_template.png')
match_result = skimage.feature.match_template(blurred, bot_template, pad_input=True)
imsave('match_result.png', match_result)
selected_area = match_result > 0.6
imsave('selected_area.png', selected_area)
ccs = find_connected_components(selected_area)
centroids = component_centroids(ccs)
return centroids
示例6: find_grains
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def find_grains(input_file, output_dir=None):
"""Return tuple of segmentaitons (grains, difficult_regions)."""
name = fpath2name(input_file)
name = "grains-" + name + ".png"
if output_dir:
name = os.path.join(output_dir, name)
image = Image.from_file(input_file)
intensity = mean_intensity_projection(image)
# Median filter seems more robust than Otsu.
# image = threshold_otsu(intensity)
image = threshold_median(intensity, scale=0.8)
image = invert(image)
image = erode_binary(image, selem=disk(2))
image = dilate_binary(image, selem=disk(2))
image = remove_small_objects(image, min_size=200)
image = fill_holes(image, min_size=50)
dist = distance(image)
seeds = local_maxima(dist)
seeds = dilate_binary(seeds) # Merge spurious double peaks.
seeds = connected_components(seeds, background=0)
segmentation = watershed_with_seeds(dist, seeds=seeds, mask=image)
# Remove spurious blobs.
segmentation = remove_large_segments(segmentation, max_size=3000)
segmentation = remove_small_segments(segmentation, min_size=100)
return segmentation
示例7: test_creating_transformations_from_scratch
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def test_creating_transformations_from_scratch(self):
# What if the default names of images was just the order in which they
# were created?
# Or perhaps the order + the function name, e.g.
# 1_gaussian.png
# 2_sobel.png
# 3_gaussian.png
# The order could be tracked in a class variable in an AutoName
# object. The AutoName object could also store the output directory
# as a class variable.
from jicbioimage.core.image import Image
from jicbioimage.core.transform import transformation
from jicbioimage.core.io import AutoName
AutoName.directory = TMP_DIR
@transformation
def identity(image):
return image
image = Image.from_file(os.path.join(DATA_DIR, 'tjelvar.png'))
image = identity(image)
self.assertEqual(len(image.history), 1, image.history)
self.assertEqual(str(image.history[-1]), '<History.Event(identity(image))>')
created_fpath = os.path.join(TMP_DIR, '1_identity.png')
self.assertTrue(os.path.isfile(created_fpath),
'No such file: {}'.format(created_fpath))
示例8: separate_plots
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def separate_plots(dataset, identifier, resource_dataset, working_dir):
fpath = dataset.item_content_abspath(identifier)
segmentation = load_segmentation_from_rgb_image(fpath)
original_id = dataset.get_overlay('from')[identifier]
original_fpath = resource_dataset.item_content_abspath(original_id)
original_image = Image.from_file(original_fpath)
approx_plot_locs = find_approx_plot_locs(dataset, identifier)
sid_to_label = generate_segmentation_identifier_to_label_map(
approx_plot_locs,
segmentation
)
outputs = []
for identifier in segmentation.identifiers:
image_section = generate_region_image(
original_image,
segmentation,
identifier
)
fname = 'region_{}.png'.format(sid_to_label[identifier])
output_fpath = os.path.join(working_dir, fname)
imsave(output_fpath, image_section)
outputs.append((fname, {'plot_number': sid_to_label[identifier]}))
return outputs
示例9: find_single_seed
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def find_single_seed(image_filename, output_filename):
image = Image.from_file(image_filename)
w, h = 500, 500
tube_section = image[1024-w:1024+w,1024-h:1024+h]
threshold = threshold_otsu(tube_section)
thresholded = tube_section > threshold
x, y, r = find_inner_circle_parameters(thresholded, 400, 500)
# FIXME - think routine is finding outer circle
stripped = strip_outside_circle(thresholded, (x, y), 300)
eroded = binary_erosion(stripped, structure=np.ones((10, 10)))
float_coords = map(np.mean, np.where(eroded > 0))
ix, iy = map(int, float_coords)
w, h = 100, 100
selected = tube_section[ix-w:ix+w,iy-h:iy+h]
with open(output_filename, 'wb') as f:
f.write(selected.view(Image).png())
示例10: annotate_single_identifier
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def annotate_single_identifier(dataset, identifier, output_path):
file_path = dataset.abspath_from_identifier(identifier)
image = Image.from_file(file_path)
grayscale = np.mean(image, axis=2)
annotated = AnnotatedImage.from_grayscale(grayscale)
xdim, ydim, _ = annotated.shape
def annotate_location(fractional_coords):
xfrac, yfrac = fractional_coords
ypos = int(ydim * xfrac)
xpos = int(xdim * yfrac)
for x in range(-2, 3):
for y in range(-2, 3):
annotated.draw_cross(
(xpos+x, ypos+y),
color=(255, 0, 0),
radius=50
)
for loc in find_approx_plot_locs(dataset, identifier):
annotate_location(loc)
output_basename = os.path.basename(file_path)
full_output_path = os.path.join(output_path, output_basename)
with open(full_output_path, 'wb') as f:
f.write(annotated.png())
示例11: find_grains
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def find_grains(input_file, output_dir=None):
"""Return tuple of segmentaitons (grains, difficult_regions)."""
name = fpath2name(input_file)
name = "grains-" + name + ".png"
if output_dir:
name = os.path.join(output_dir, name)
image = Image.from_file(input_file)
intensity = mean_intensity_projection(image)
image = remove_scalebar(intensity, np.mean(intensity))
image = threshold_abs(image, 75)
image = invert(image)
image = fill_holes(image, min_size=500)
image = erode_binary(image, selem=disk(4))
image = remove_small_objects(image, min_size=500)
image = dilate_binary(image, selem=disk(4))
dist = distance(image)
seeds = local_maxima(dist)
seeds = dilate_binary(seeds) # Merge spurious double peaks.
seeds = connected_components(seeds, background=0)
segmentation = watershed_with_seeds(dist, seeds=seeds, mask=image)
# Need a copy to avoid over-writing original.
initial_segmentation = np.copy(segmentation)
# Remove spurious blobs.
segmentation = remove_large_segments(segmentation, max_size=3000)
segmentation = remove_small_segments(segmentation, min_size=500)
props = skimage.measure.regionprops(segmentation)
segmentation = remove_non_round(segmentation, props, 0.6)
difficult = initial_segmentation - segmentation
return segmentation, difficult
示例12: generate_composite_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def generate_composite_image(base_image, trajectory_image):
still_image = Image.from_file(base_image)
trajectories = Image.from_file(trajectory_image)[:,:,0]
annotation_points = np.where(trajectories != 0)
color = 255, 0, 0
for x, y in zip(*annotation_points):
still_image[x, y] = color
still_image[x+1, y] = color
still_image[x-1, y] = color
still_image[x, y+1] = color
still_image[x, y-1] = color
imsave('annotated_image.png', still_image)
示例13: labels_to_joined_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def labels_to_joined_image(labels):
images = []
for plot_label in labels:
image_fpath = dataset.item_content_abspath(label_to_id[plot_label])
image = Image.from_file(image_fpath)
images.append(image)
return join_horizontally(images)
示例14: load_and_downscale
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def load_and_downscale(input_filename):
"""Load the image, covert to grayscale and downscale as needed."""
image = Image.from_file(input_filename)
blue_channel = image[:,:,2]
downscaled = downscale_local_mean(blue_channel, (2, 2))
return downscaled
示例15: identifiers_to_joined_image
# 需要导入模块: from jicbioimage.core.image import Image [as 别名]
# 或者: from jicbioimage.core.image.Image import from_file [as 别名]
def identifiers_to_joined_image(identifiers):
images = []
for identifier in identifiers:
image_fpath = dataset.item_content_abspath(identifier)
image = Image.from_file(image_fpath)
images.append(image)
return join_horizontally(images)