Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(np.shape(loadedImage)) == 2:
maskImage = loadedImage
else:
maskImage = loadedImage[:, :, 0]
except:
return None, None, 1
mask = np.zeros([maskImage.shape[0], maskImage.shape[1], 1])
# TODO: Take a look to resizing in square, etc. modes
maskAppend = np.zeros([maskImage.shape[0], maskImage.shape[1], 1])
class_ids = np.array([self.classes[a[0].split('-')[-2]]])
mask[:, :, 0] = maskImage.astype(np.bool)
for i in range(1, len(a)):
np.append(class_ids, self.classes[a[i].split('-')[-2]])
try:
loadedImage = skimage.io.imread(a[0])
if len(np.shape(loadedImage)) == 2:
maskAppend[:, :, 0] = loadedImage.astype(np.bool)
else:
maskAppend[:, :, 0] = loadedImage[:, :, 0].astype(np.bool)
except:
return None, None, 1
np.concatenate((mask, maskAppend), 2)
return mask, class_ids, 0
def __getitem__(self, idx):
src_file = self.srcpath % self.datalist[idx]
tar_file = self.tarpath % self.datalist[idx]
src = imread(src_file)
tar = imread(tar_file)
assert len(tar.shape) == 2, "Mask should be 2D."
tar_sub = vision.shift_edge(tar, self.tar_ch)
# src => uint8 to float tensor
src = (src / 255).transpose((2, 0, 1))
src = torch.from_numpy(src).float()
# tar => uint8 to float tensor
tar = vision.cls_to_label(tar, self.tar_ch).transpose((2, 0, 1))
tar = torch.from_numpy(tar).float()
# tar_sub => float to float tensor
tar_sub = tar_sub.transpose((2, 0, 1))
tar_sub = torch.from_numpy(tar_sub).float()
sample = {"src":src,
"tar":tar,
"tar_sub":tar_sub,
}
return sample
dividing pixel values by the bit depth of the images.
Parameters
----------
input_file : str
Path and filename to the TIF image/stack.
normalize : bool
Determines whether the images will be normalized.
Returns
-------
data : array_like
The normalized array of images.
"""
data = io.imread(input_file)
if data.ndim == 3:
data = data[:, :, :, np.newaxis]
elif data.ndim == 2:
data = data[np.newaxis, :, :, np.newaxis]
else:
raise ImageDimError('Tiff image should be grayscale and 2D '
'(3D if stack)')
# Converting from uint to float
if data.dtype == 'uint8':
max_uint = 255
elif data.dtype == 'uint16':
max_uint = 2 ** 16 - 1
else:
raise ImageTypeError('Tiff image type should be uint8 or uint16')
data = data.astype('float')
def img_load(path,w,h,resize=True):
img = skimage.io.imread(path)
if len(img.shape) == 2:
img = np.dstack((img,img,img))
if resize:
img = resize(img,(w,h)).astype(np.uint8)
img = cvtColor(img,COLOR_BGR2RGB)
return img
for i in range(num_point):
for j in range(2):
src[i][j]=points[k]
k=k+1
#根据检测到的点,求其相应的仿射变换矩阵
tfrom=tf.estimate_transform('affine',dst,src)
#用opencv的试试,其只能采用三个点,计算矩阵M
# pts1 = np.float32([[src[0][0],src[0][1]],[src[1][0],src[1][1]],[src[2][0],src[2][1]]])
# pts2 = np.float32([[dst[0][0],dst[0][1]],[dst[1][0],dst[1][1]],[dst[2][0],dst[2][1]]])
# M = cv2.getAffineTransform(pts2,pts1)
#用最小二乘法的方法进行处理
pts3 = np.float32([[src[0][0],src[0][1]],[src[1][0],src[1][1]],[src[2][0],src[2][1]],[src[3][0],src[3][1]],[src[4][0],src[4][1]]])
pts4 = np.float32([[dst[0][0],dst[0][1]],[dst[1][0],dst[1][1]],[dst[2][0],dst[2][1]],[dst[3][0],dst[3][1]],[dst[4][0],dst[4][1]]])
N = compute_affine_transform(pts4,pts3)
#
im=skimage.io.imread(filename)
if im.ndim==3:
rows,cols,ch = im.shape
else:
rows,cols = im.shape
warpimage_cv2 = cv2.warpAffine(im,N,(cols,rows))
warpimage=tf.warp(im,inverse_map=tfrom)
return warpimage,warpimage_cv2
Boldly copied from the caffe.io routine load_image: https://github.com/BVLC/caffe/blob/master/python/caffe/io.py
Parameters
----------
filename : string
color : boolean
flag for color format. True (default) loads as RGB while False
loads as intensity (if image is already grayscale).
Returns
-------
image : an image with type np.float32 in range [0, 1]
of size (H x W x 3) in RGB or
of size (H x W x 1) in grayscale.
"""
img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
if img.ndim == 2:
img = img[:, :, np.newaxis]
if color:
img = np.tile(img, (1, 1, 3))
elif img.shape[2] == 4:
img = img[:, :, :3]
return img
def bytes_to_array(bstring):
if bstring is None:
return onfail()
try:
fd = NamedTemporaryFile(prefix='gbdxtools', suffix='.tif', delete=False)
fd.file.write(bstring)
fd.file.flush()
fd.close()
arr = imread(fd.name)
if len(arr.shape) == 3:
arr = np.rollaxis(arr, 2, 0)
else:
arr = np.expand_dims(arr, axis=0)
except Exception as e:
arr = on_fail()
finally:
fd.close()
os.remove(fd.name)
return arr
import redisai as rai
from skimage import io
import json
con = rai.Client(host='159.65.150.75', port=6379, db=0)
img_path = '../models/imagenet/data/cat.jpg'
class_idx = json.load(open("../models/imagenet/data/imagenet_classes.json"))
image = io.imread(img_path)
tensor = rai.BlobTensor.from_numpy(image)
out3 = con.tensorset('image', tensor)
out4 = con.scriptrun('imagenet_script', 'pre_process', 'image', 'temp1')
out5 = con.modelrun('imagenet_model', 'temp1', 'temp2')
out6 = con.scriptrun('imagenet_script', 'post_process', 'temp2', 'out')
final = con.tensorget('out')
ind = final.value[0]
print(ind, class_idx[str(ind)])
def read(self, time):
'''
read image according to time
Args:
time: current timepoint
Returns:
image_stack: tiff image list
'''
image_stack = io.imread('./embryo_8bit.tif')
return image_stack