def rescale(root_new, root_old, img_path, ann_path, out_shape):
    try:
        img = io.imread(root_old + "/" + img_path)
    except Exception as E:
        print E
    h, w, _ = img.shape
    f_h, f_w = float(out_shape) / h, float(out_shape) / w
    trans_img = transform.rescale(img, (f_h, f_w))
    num_objs = 0
    with open(root_old + "/" + ann_path, 'r') as f:
        ann = f.readline()
        ann = ann.rstrip()
        ann = ann.split(' ')
        ann = [float(i) for i in ann]
        num_objs = len(ann) / 5
        for idx in xrange(num_objs):
            ann[idx * 5 + 0] = int(f_w * ann[idx * 5 + 0])
            ann[idx * 5 + 1] = int(f_h * ann[idx * 5 + 1])
            ann[idx * 5 + 2] = int(f_w * ann[idx * 5 + 2])
            ann[idx * 5 + 3] = int(f_h * ann[idx * 5 + 3])
        # Write the new annotations to file
        with open(root_new + "/" + ann_path, 'w') as f_new:
            for val in ann:
                f_new.write(str(val) + ' ')
    # Save the new image
    io.imwrite(root_new + "/" + img_path, trans_img)
def rescale(root_new, root_old, img_path, ann_path, out_shape):
  try:
    img = io.imread(root_old+"/"+img_path)
  except Exception as E:
    print E
  h, w, _ = img.shape
  f_h, f_w = float(out_shape)/h, float(out_shape)/w
  trans_img = transform.rescale(img, (f_h, f_w))
  num_objs = 0
  with open(root_old+"/"+ann_path, 'r') as f:
    ann = f.readline()
    ann = ann.rstrip()
    ann = ann.split(' ')
    ann = [float(i) for i in ann]
    num_objs = len(ann) / 5
    for idx in xrange(num_objs):
      ann[idx * 5 + 0] = int(f_w * ann[idx * 5 + 0])
      ann[idx * 5 + 1] = int(f_h * ann[idx * 5 + 1])
      ann[idx * 5 + 2] = int(f_w * ann[idx * 5 + 2])
      ann[idx * 5 + 3] = int(f_h * ann[idx * 5 + 3])
    # Write the new annotations to file
    with open(root_new+"/"+ann_path, 'w') as f_new:
      for val in ann:
        f_new.write(str(val)+' ')
  # Save the new image
  io.imwrite(root_new+"/"+img_path, trans_img)
Beispiel #3
0
def imwrite(path, im):
    try:
        import cv2
        return cv2.imwrite(path, im)
    except ImportError:
        pass
    from skimage import io
    return io.imwrite(path, im)
Beispiel #4
0
    recon[:] = obj.tv_loop(recon, dPOCS, ng)

    dg = np.linalg.norm(recon - temp_recon)

    if (dg > dp * r_max and dd_vec[i] > eps):
        dPOCS *= alpha_red

    tv_vec[i] = tv(recon)
    rmse_vec[i] = np.sqrt(((recon - img0)**2).mean())

    if ((i + 1) % 300 == 0):

        if save:  #save image
            recon[recon < 0] = 0
            io.imwrite('eps_' + str(round(eps, 2)) + '_' + file_name,
                       np.uint16(recon))

        # add new epsilon parameters
        eps_vec[eps_ind, :] = (eps, i)
        eps_ind += 1
        eps -= 5
        beta = 0.3
        recalc_l2 = True

if save:
    file_name = file_name.replace('.tif', '')
    np.save('Results/dyn_eps.npy', eps_vec)
    np.save('Results/dyn_tv.npy', tv_vec)
    np.save('Results/dyn_dd.npy', dd_vec)
    np.save('Results/dyn_rmse.npy', rmse_vec)
Beispiel #5
0
# In[14]:

kernel = load_kernel_from_file(ctx, '../datas/cl/rgb2gray.cl')

# In[ ]:

imageFormat = cl.ImageFormat(cl.channel_order.RGBA,
                             cl.channel_type.UNSIGNED_INT8)
img_in_dev = copy_image_to_device_readonly(ctx, src, imageFormat)

# In[10]:

img_out_dev = create_device_write_only_image(ctx, imageFormat,
                                             (src.shape[0], src.shape[1]))

# In[14]:

local_work_size = (8, 8)
global_work_size = (cal_work_size(local_work_size[0], src.shape[0]),
                    cal_work_size(local_work_size[1], src.shape[1]))
print(local_work_size, global_work_size)
kernel.gray_avg_filter(queue, global_work_size, local_work_size, img_in_dev,
                       img_out_dev)

# In[16]:

output = copy_image_to_host(queue, img_out_dev, (src.shape[0], src.shape[1]),
                            np.uint8)
skio.imwrite('../temp/cl_output.jpg')
import os
import sys
from skimage import io
from modules.histogramNormalizing import matchHistograms

reference = sys.argv[1]
target = sys.argv[2]
prefix = os.path.splitext(reference)[0]
matched = matchHistograms(reference, target)
io.imwrite(f"{prefix}_matched.tif", matched)
Beispiel #7
0
def write_image(datapath, timestamp, imraw):
    filename = os.path.join(datapath,
                            timestamp.strftime('D%Y%m%dT%H%M%S.%f.bmp'))
    imwrite(filename, np.uint8(imraw))
    logger.info('Image written')