예제 #1
0
def convert_to_rgb(df, split, resize=True, new_size=224, extension='jpeg'):
    N = df.shape[0]

    for i in tqdm(range(N)):
        code = df['id_code'][i]
        experiment = df['experiment'][i]
        plate = df['plate'][i]
        well = df['well'][i]

        for site in [1, 2]:
            save_path = os.path.join(
                BASE_DIR, '{}/{}_s{}.{}'.format(split, code, site, extension))

            im = rio.load_site_as_rgb(split,
                                      experiment,
                                      plate,
                                      well,
                                      site,
                                      base_path=ORI_DIR)
            im = im.astype(np.uint8)
            im = Image.fromarray(im)

            if resize:
                im = im.resize((new_size, new_size), resample=Image.BILINEAR)

            im.save(save_path)
예제 #2
0
def moving_files(df=x_train_df, mode='train'):
    indexes = df.index
    bar = Bar(mode + '_processing', max=len(df))
    for i in tqdm.tqdm(range(len(df))):
        row = df.iloc[i, :]
        class_name = str(int(row['sirna']))
        create_folder(mode + '_data/' + class_name)
        img = rio.load_site_as_rgb('train', row['experiment'], row['plate'],
                                   row['well'], row['site'])
        img = img.astype(np.uint8)
        dest = mode + '_data/' + class_name + '/' + indexes[i] + '_' + str(
            row['site']) + '.png'
        plt.imsave(dest, img)
        bar.next()
    bar.finish()
def moving_files(df,t,mode='test'):
    indexes = df.index
    bar = Bar(t, max=len(df))
    for i in tqdm.tqdm(range(len(df))):
        row = df.iloc[i,:]
        img = rio.load_site_as_rgb(mode,
                                    row['experiment'],
                                    row['plate'],
                                    row['well'],
                                    row['site'])
        img = img.astype(np.uint8)
        dest = mode+'_data/test/'+indexes[i]+'_'+str(row['site'])+'.png'
        bar.next()
        plt.imsave(dest,img)
    bar.finish()
예제 #4
0
def convert_to_rgb(df, split, resize=True, new_size=400, extension='jpeg'):
    N = df.shape[0]

    for i in tqdm(range(N)):
        code = df['id_code'][i]
        experiment = df['experiment'][i]
        plate = df['plate'][i]
        well = df['well'][i]

        for site in [1, 2]:
            save_path = f'rxrxrgb/{split}/{code}_s{site}.{extension}'

            im = rio.load_site_as_rgb(
                    split, experiment, plate, well, site, 
                    base_path=data_path
                    )
            im = im.astype(np.uint8)
            im = Image.fromarray(im)

            if resize:
                im = im.resize((new_size, new_size), resample=Image.BILINEAR)
            im.save(save_path)
예제 #5
0
def convert_to_rgb_(cell):
    split = cell.split
    code = cell.code
    site = cell.site
    extension = cell.extension
    experiment = cell.experiment
    plate = cell.plate
    well = cell.well

    save_path = f'{split}/{code}_s{site}.{extension}'

    im = rio.load_site_as_rgb(split,
                              experiment,
                              plate,
                              well,
                              site,
                              base_path='./data/')
    im = im.astype(np.uint8)
    im = Image.fromarray(im)

    # im = im.resize((512, 512), resample=Image.BILINEAR)

    im.save(save_path)
예제 #6
0
def convert_to_rgb(df, split, resize=False, new_size=224, extension='png'):
    RGB_MAP = {
        1: {
            'rgb': np.array([19, 0, 249]),
            'range': [0, 51]
        },
        2: {
            'rgb': np.array([42, 255, 31]),
            'range': [0, 107]
        },
        3: {
            'rgb': np.array([255, 0, 25]),
            'range': [0, 64]
        },
        4: {
            'rgb': np.array([45, 255, 252]),
            'range': [0, 191]
        },
        5: {
            'rgb': np.array([250, 0, 253]),
            'range': [0, 89]
        },
        6: {
            'rgb': np.array([254, 255, 40]),
            'range': [0, 191]
        }
    }

    N = df.shape[0]

    print(df.head())
    print(df['id_code'].iloc[1])
    for i in tqdm(range(N)):

        code = df['id_code'].iloc[i]
        experiment = df['experiment'].iloc[i]
        plate = df['plate'].iloc[i]
        well = df['well'].iloc[i]
        sirna = df['sirna'].iloc[i]

        for site in [1, 2]:

            folder = '../input/' + str(split) + '/' + str(sirna) + '/'

            if not os.path.exists(folder):
                os.makedirs(folder)

            save_path = '../input/' + str(split) + '/' + str(
                sirna) + '/' + str(code) + '_s' + str(site) + '.' + str(
                    extension)

            im = rio.load_site_as_rgb(split,
                                      experiment,
                                      plate,
                                      well,
                                      site,
                                      channels=(1, 2, 3, 4, 5, 6),
                                      base_path='../input/',
                                      rgb_map=RGB_MAP)
            im = im.astype(np.uint8)
            im = Image.fromarray(im)

            if resize:
                im = im.resize((new_size, new_size), resample=Image.BILINEAR)

            im.save(save_path)
x = rio.convert_tensor_to_rgb(t)

x.shape

# In[7]:

plt.figure(figsize=(8, 8))
plt.axis('off')

_ = plt.imshow(x)

# In[8]:

y = rio.load_site_as_rgb('train',
                         'HUVEC-08',
                         4,
                         'K09',
                         1,
                         base_path=LOCAL_IMAGES_BASE_PATH)

plt.figure(figsize=(8, 8))
plt.axis('off')

_ = plt.imshow(y)

# In[9]:

# train.csv, train_controls.csv, test.csv, test_controls.csv

md = rio.combine_metadata(base_path=DEFAULT_METADATA_BASE_PATH)

md.head()
예제 #8
0
import rxrx.io as rio
t = rio.load_site('train', 'RPE-05', 3, 'D19', 2)
t.shape
fig, axes = plt.subplots(2, 3, figsize=(24, 16))

for i, ax in enumerate(axes.flatten()):
    ax.axis('off')
    ax.set_title('channel {}'.format(i + 1))
    _ = ax.imshow(t[:, :, i], cmap='gray')
x = rio.convert_tensor_to_rgb(t)
x.shape
plt.figure(figsize=(8, 8))
plt.axis('off')

_ = plt.imshow(x)
y = rio.load_site_as_rgb('train', 'HUVEC-08', 4, 'K09', 1)

plt.figure(figsize=(8, 8))
plt.axis('off')

_ = plt.imshow(y)
md = rio.combine_metadata()
md.head()
import seaborn as sns
md.head(10)
md.index
for i in md.columns:
    print(">> ", i, "\t", md[i].unique())
for col in [
        'cell_type', 'dataset', 'experiment', 'plate', 'site', 'well_type'
]: