Ejemplo n.º 1
0
def plot_poly_gate(data, gate, ax, chan=None, name=None, **kwargs):
    if chan is None:
        chan = gate.chan

    if 'bgc' in kwargs:
        bgc = kwargs['bgc']
        del kwargs['bgc']
    else:
        bgc = 'grey'

    if 'bgalpha' in kwargs:
        bga = kwargs['bgalpha']
        del kwargs['bgalpha']
    else:
        bga = 1

    if 'c' in kwargs:
        z = kwargs['c']
        del kwargs['c']  # needed incase bgc is used
        calc_z = False
    else:
        calc_z = True

    if 'alpha' in kwargs:
        alpha = kwargs['alpha']
        del kwargs['alpha']
    else:
        # is there a way to look up what this defaults to incase this is
        # changed in .matplotlibrc?
        alpha = 1

    # add in support for specifing size

    ax.scatter(data[:, chan[0]],
               data[:, chan[1]],
               c=bgc,
               s=1,
               edgecolor='none',
               alpha=bga)
    gate.gate(data, chan=chan, name=name)

    # has to be set after gating...

    if data.shape[0] > 0:
        if calc_z:
            z = bilinear_interpolate(data[:, chan[0]], data[:, chan[1]])

        ax.scatter(data[:, chan[0]],
                   data[:, chan[1]],
                   c=z,
                   s=1,
                   edgecolor='none',
                   alpha=alpha,
                   **kwargs)

    ax.fill(gate.vert.T[0],
            gate.vert.T[1],
            edgecolor='black',
            facecolor='none')
Ejemplo n.º 2
0
def pseudocolor(fcm,
                indices,
                nrows=1,
                ncols=1,
                s=1,
                edgecolors='none',
                savefile=None,
                display=True,
                **kwargs):
    """Plot a pseudocolor.

    indices = list of marker index pairs
    nrows = number of rows to plot
    ncols = number of cols to plot
    nrows * ncols should be >= len(indices)
    display = boolean indicating whether to show plot
    save = filename to save plot (e.g. 'x.png')
    **kwargs are passed on to pylab.scatter
    """

    if nrows == 1 and ncols == 1:
        ncols = len(indices)

    assert (nrows * ncols >= len(indices))

    figure = pylab.figure(figsize=(ncols * 4, nrows * 4))

    for i, idx in enumerate(indices):
        pylab.subplot(nrows, ncols, i + 1)
        if (idx[0] != idx[1]):
            x = fcm[:, idx[0]]
            y = fcm[:, idx[1]]
            if 'c' not in kwargs:
                z = bilinear_interpolate(x, y)
                pylab.scatter(x, y, c=z, s=s, edgecolors=edgecolors, **kwargs)
            else:
                pylab.scatter(x, y, s=s, edgecolors=edgecolors, **kwargs)
            if isinstance(idx[0], str):
                pylab.xlabel(idx[0])
            else:
                pylab.xlabel(fcm.channels[idx[0]])

            if isinstance(idx[1], str):
                pylab.ylabel(idx[1])
            else:
                pylab.ylabel(fcm.channels[idx[1]])
        pylab.xticks([])
        pylab.yticks([])
        pylab.axis('equal')

    if display:
        pylab.show()

    if savefile:
        pylab.savefig(savefile)

    return figure
Ejemplo n.º 3
0
Archivo: plot.py Proyecto: whitews/fcm
def pseudocolor(fcm, indices, nrows=1, ncols=1, s=1, edgecolors='none',
            savefile=None, display=True,
            **kwargs):
    """Plot a pseudocolor.

    indices = list of marker index pairs
    nrows = number of rows to plot
    ncols = number of cols to plot
    nrows * ncols should be >= len(indices)
    display = boolean indicating whether to show plot
    save = filename to save plot (e.g. 'x.png')
    **kwargs are passed on to pylab.scatter
    """

    if nrows == 1 and ncols == 1:
        ncols = len(indices)

    assert(nrows * ncols >= len(indices))

    figure = pylab.figure(figsize=(ncols * 4, nrows * 4))

    for i, idx in enumerate(indices):
        pylab.subplot(nrows, ncols, i + 1)
        if (idx[0] != idx[1]):
            x = fcm[:, idx[0]]
            y = fcm[:, idx[1]]
            if 'c' not in kwargs:
                z = bilinear_interpolate(x, y)
                pylab.scatter(x, y, c=z, s=s, edgecolors=edgecolors, **kwargs)
            else:
                pylab.scatter(x, y, s=s, edgecolors=edgecolors, **kwargs)
            if isinstance(idx[0], str):
                pylab.xlabel(idx[0])
            else:
                pylab.xlabel(fcm.channels[idx[0]])
                
            if isinstance(idx[1], str):
                pylab.ylabel(idx[1])
            else:
                pylab.ylabel(fcm.channels[idx[1]])
        pylab.xticks([])
        pylab.yticks([])
        pylab.axis('equal')

    if display:
        pylab.show()

    if savefile:
        pylab.savefig(savefile)

    return figure
Ejemplo n.º 4
0
def plot_threshold_gate(data, gate, ax, chan=None, name=None, **kwargs):
   
    if 'bgc' in kwargs:
        bgc = kwargs['bgc']
        del kwargs['bgc']
    else:
        bgc = 'grey'
        
    if 'bgalpha' in kwargs:
        bga = kwargs['bgalpha']
        del kwargs['bgalpha']
    else:
        bga = 1

    if 'c' in kwargs:
        z = kwargs['c']
        del kwargs['c'] # needed incase bgc is used
        calc_z = False
    else:
        calc_z = True
        
    if 'alpha' in kwargs:
        alpha = kwargs['alpha']
        del kwargs['alpha']
    else:
        alpha = 1 # is there a way to look up what this defaults to incase this is changed in .matplotlibrc?

    # add in support for specifing size
    
    ax.scatter(data[:,chan[0]],data[:,chan[1]], c=bgc, s=1, edgecolor='none', alpha=bga)
    gate.gate(data, name=name)
    
    #has to be set after gating...

    if data.shape[0] > 0:
        if calc_z:
            z = bilinear_interpolate(data[:, chan[0]], data[:, chan[1]])  

        ax.scatter(data[:,chan[0]],data[:,chan[1]], c=z, s=1, edgecolor='none', alpha=alpha, **kwargs)
    
    if chan[0] == gate.chan:
        ax.axvline(gate.vert)
    elif chan[1] == gate.chan:
        ax.axhline(gate.vert)
Ejemplo n.º 5
0
def plot_poly_gate(data, gate, ax, chan=None, name=None, **kwargs):
    if chan is None:
        chan = gate.chan

    if 'bgc' in kwargs:
        bgc = kwargs['bgc']
        del kwargs['bgc']
    else:
        bgc = 'grey'

    if 'bgalpha' in kwargs:
        bga = kwargs['bgalpha']
        del kwargs['bgalpha']
    else:
        bga = 1

    if 'c' in kwargs:
        z = kwargs['c']
        del kwargs['c']  # needed incase bgc is used
        calc_z = False
    else:
        calc_z = True

    if 'alpha' in kwargs:
        alpha = kwargs['alpha']
        del kwargs['alpha']
    else:
        # is there a way to look up what this defaults to incase this is
        # changed in .matplotlibrc?
        alpha = 1

    # add in support for specifing size

    ax.scatter(
        data[
            :,
            chan[0]],
        data[
            :,
            chan[1]],
        c=bgc,
        s=1,
        edgecolor='none',
        alpha=bga)
    gate.gate(data, chan=chan, name=name)

    # has to be set after gating...

    if data.shape[0] > 0:
        if calc_z:
            z = bilinear_interpolate(data[:, chan[0]], data[:, chan[1]])

        ax.scatter(
            data[
                :,
                chan[0]],
            data[
                :,
                chan[1]],
            c=z,
            s=1,
            edgecolor='none',
            alpha=alpha,
            **kwargs)

    ax.fill(
        gate.vert.T[0],
        gate.vert.T[1],
        edgecolor='black',
        facecolor='none')
Ejemplo n.º 6
0
def main(_):

    with tf.Graph().as_default():
        #Load image and label
        x = tf.placeholder(
            shape=[None, FLAGS.resizedheight, FLAGS.resizedwidth, 11],
            dtype=tf.float32)

        img_list = sorted(glob(FLAGS.dataset_dir + '/*.jpg'))

        # # Define the model:
        with tf.variable_scope("model") as scope:
            with tf.name_scope("depth_prediction"):
                #with tf.variable_scope("depth_prediction") as scope:

                pred_disp, depth_net_endpoints = depth_net(x,
                                                           is_training=False)

                # predictions, end_points = resnet_v2.resnet_v2_50(x,
                #                                           global_pool=False,
                #                                           is_training=False
                #                                           )

                # multilayer = [end_points['model/resnet_v2_50/block4'],
                #               end_points['model/resnet_v2_50/block2'],
                #               end_points['model/resnet_v2_50/block1'],
                #               end_points['model/depth_prediction/resnet_v2_50/block1/unit_3/bottleneck_v2/conv1'],
                #               end_points['model/depth_prediction/resnet_v2_50/conv1']]

                # pred_disp = upconvolution_net(multilayer,is_training=False)

                saver = tf.train.Saver([var for var in tf.model_variables()])
                #import pdb;pdb.set_trace()
                checkpoint = tf.train.latest_checkpoint(FLAGS.checkpoint_dir)

            with tf.Session() as sess:

                saver.restore(sess, checkpoint)
                #import pdb;pdb.set_trace()
                for i in range(len(img_list) - 1):

                    fh = open(img_list[i], 'r')
                    I = pil.open(fh)
                    I = np.array(I)
                    #I = cv2.resize(I,(FLAGS.resizedwidth,FLAGS.resizedheight),interpolation = cv2.INTER_AREA)

                    fh = open(img_list[i + 1], 'r')
                    I1 = pil.open(fh)
                    I1 = np.array(I1)

                    # fh = open(img_list[i],'r')
                    # I = pil.open(fh)

                    # I = np.array(I)

                    # I1 = I[:,720:,:]
                    # I = I[:,:720,:]

                    #I1 = cv2.resize(I1,(FLAGS.resizedwidth,FLAGS.resizedheight),interpolation = cv2.INTER_AREA)

                    #I = I.resize((224,224),pil.ANTIALIAS)

                    #I = I/255.0

                    #import pdb;pdb.set_trace()
                    #Optical flow
                    #flow=np.fromfile(FLAGS.dataset_dir+'/2342_2373.flo.flo', dtype=np.float32).reshape( I1.shape[0],I1.shape[1],2)
                    flow = util.readFlow(FLAGS.dataset_dir + '/z.flo')

                    #flow = np.zeros_like(flow)

                    x_coord = np.repeat(
                        np.reshape(
                            np.linspace(0, I1.shape[1] - 1, I1.shape[1]),
                            [1, I1.shape[1]]), I1.shape[0], 0)
                    y_coord = np.repeat(
                        np.reshape(
                            np.linspace(0, I1.shape[0] - 1, I1.shape[0]),
                            [I1.shape[0], 1]), I1.shape[1], 1)

                    x_coord = x_coord + flow[:, :, 0]
                    y_coord = y_coord + flow[:, :, 1]

                    #Bilinear interpolation
                    I_warp, _ = util.bilinear_interpolate(
                        I1, np.reshape(x_coord, -1), np.reshape(y_coord, -1))
                    I_warp = I_warp.reshape(I1.shape[0], I1.shape[1], 3)
                    I_warp = I_warp.astype(np.float32)
                    I = I.astype(np.float32)
                    I1 = I1.astype(np.float32)

                    #I_warp = np.zeros_like(I1)
                    #I1 = np.zeros_like(I1)
                    #I = np.zeros_like(I1)
                    inputdata = np.concatenate([I, I1, flow, I_warp], axis=2)

                    pred = sess.run(pred_disp,
                                    feed_dict={x: inputdata[None, :, :, :]})
                    #test = np.asarray(pred[4])
                    import pdb
                    pdb.set_trace()

                    #import pdb;pdb.set_trace()
                    #z = pred[0][0][0][0,:,:,:]
                    z = pred[0][0, :, :, 0]
                    #z=cv2.resize(pred[0][0,:,:,:],(FLAGS.image_width,FLAGS.image_height),interpolation = cv2.INTER_CUBIC)
                    #z = cv2.bilateralFilter(z,9,75,75)
                    #z=1.0/z#[0][0,:,:,0]
                    z.astype(np.float32).tofile(FLAGS.output_dir +
                                                img_list[i].split('/')[-1] +
                                                '_z.bin')

                    print("The %dth frame is processed" % (i))