예제 #1
0
    def preprocess(self, image):
        image = resize(image,
                       (self.inp_shape[1],
                        self.inp_shape[2]))  # rescale to match the input size

        # change to grayscale if the model is in grayscale
        if self.inp_shape[3] == 1 and image.shape[2] != 1:
            if image.shape[2] == 3:
                image = rgb_to_grayscale(image)
            elif image.shape[2] == 4:
                image = rgb_to_grayscale(image[:, :, :3])

        image = img_to_array(image)
        image = np.expand_dims(image, axis=0)
        return image
예제 #2
0
def __random_circles_image(fig, circle_num, get_radius=__get_radius):
    ax = fig.add_axes([0, 0, 1, 1], frameon=False)
    ax.set_xlim(0, SIDE_LIMIT)
    ax.set_ylim(0, SIDE_LIMIT)
    ax.axis('off')

    circle_params = []
    for _ in range(circle_num):
        radius = get_radius()
        center = __random_center(circle_params, radius)
        circle_param = {'r': radius, 'c': center}
        circle_params.append(circle_param)
        circle = ptchs.Circle(center, radius, fill=False)
        ax.add_artist(circle)

    canvas = fig.canvas
    canvas.draw()
    fig_size = fig.get_size_inches()
    fig_dpi = fig.get_dpi()
    width, height = fig_size * fig_dpi
    data = np.fromstring(canvas.tostring_rgb(), np.uint8).reshape(
        (int(height), int(width), 3))
    data = tfimg.rgb_to_grayscale(data)
    data = np.squeeze(data)
    fig.clf()
    return data
def grayscale_and_resize(PIL, shape=(256, 256), padding=False, grayscale=True):
    """
    This is the preprocessing function that will take the raw jpeg, gray scale it, resize it and 
    turn it into an array
    
    
    PIL --> PIL object
    shape --> tuple: size of the final array
    padding --> bool: if True, will use tf.resize_with_pad
    """
    if padding:
        gray_image = rgb_to_grayscale(PIL)
        resized_image_arr = resize_with_pad(gray_image,
                                            target_height=shape[0],
                                            target_width=shape[1])
    else:
        if grayscale:
            resized_image_arr = img_to_array(
                PIL.convert(mode='L').resize(shape))
        else:
            resized_image_arr = img_to_array(PIL.resize(shape))

    return resized_image_arr
예제 #4
0
        hsv_image = cv2.cvtColor(frame3, cv2.COLOR_BGR2HSV)
        hsv_image[:, :, 2] = cv2.equalizeHist(hsv_image[:, :, 2])
        histEqualized_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR)

        cv2.putText(histEqualized_image, 'Histogram equalization', (10, 30),
                    font, 1, (0, 0, 255), 1)

        result3 = histEqualized_image

        ###########Gray#############

        frame4 = cv2.resize(frame4, (width // 2, height // 2))

        enable_eager_execution()
        image_data = rgb_to_grayscale(frame4)
        image_data_array = image_data.numpy()

        result4 = cv2.cvtColor(image_data_array, cv2.COLOR_GRAY2BGR)

        cv2.putText(result4, 'Gray', (10, 30), font, 1, (0, 0, 255), 1)

        ###########################

        up_frame = np.hstack((frame1, result2))
        down_frame = np.hstack((result3, result4))
        result_video = np.vstack((up_frame, down_frame))

        out.write(result_video)
    else:
        break
from tflearn import fully_connected, regression, input_data, dropout
from tensorflow import image

FOLDER = '/home/jer/Workspace/cs5600/project1/trained_nets/'
NAME = 'ANN_Bee2_1S_5Layer_relu_grayscale'
SAVE_POINT = f'{FOLDER}' + f'{NAME}' + '.tfl'
CHECK_POINT = SAVE_POINT + '.meta'

beeX, beeY = tflearn.data_utils.image_preloader('BEE2_1S/class_labels.txt',
                                                image_shape=(90, 90),
                                                mode='file',
                                                categorical_labels=True,
                                                normalize=True)

input_layer = input_data(shape=[None, 90, 90, 3])
input_layer = image.rgb_to_grayscale(input_layer)
fc_layer_1 = fully_connected(input_layer,
                             8100,
                             activation='relu',
                             name='fc_layer_1')
dropout_1 = dropout(fc_layer_1, 0.5)
fc_layer_2 = fully_connected(dropout_1,
                             4000,
                             activation='relu',
                             name='fc_layer_2')
dropout_2 = dropout(fc_layer_2, 0.5)
fc_layer_3 = fully_connected(dropout_2,
                             500,
                             activation='relu',
                             name='fc_layer_3')
dropout_3 = dropout(fc_layer_3, 0.5)
예제 #6
0
def rgb255_to_obj_net(rgb):

    input_x_ = ContrastNoise(0.25)(rgb)
    input_x_ = ContrastNoiseSingle(0.25)(input_x_)
    input_x_ = GaussianNoise(.08 * 128)(input_x_)
    input_x_ = BrightnessNoise(0.2 * 128)(input_x_)

    rgb = Lambda(lambda x: rgb_to_grayscale(x) / 255.)(input_x_)

    x = Conv2D(8, 5, padding='same', activation='selu')(rgb)
    tier0 = x

    x = Conv2D(16, 5, strides=2, padding='same', activation='selu')(x)
    x = dense_block(x, 32, 3)
    tier1 = x

    x = Conv2D(64, 5, strides=2, padding='same', activation='selu')(x)
    x = dense_block(x, 64, 6)
    x = dense_block(x, 64, 6)
    tier2 = x

    x = Conv2D(128, 5, strides=2, padding='same', activation='selu')(x)
    x = dense_block(x, 64, 12)
    x = dense_block(x, 64, 12)
    tier3 = x

    x = Conv2D(128, 5, strides=2, padding='same', activation='selu')(x)
    x = dense_block(x, 128, 12)

    def up_path(x):
        x = UpSampling2D()(x)
        x = Concatenate()([x, tier3])
        x = Conv2D(64, 3, padding='same', activation='selu')(x)
        x = dense_block(x, 32, 12)

        x = UpSampling2D()(x)
        x = Concatenate()([x, tier2])
        x = Conv2D(32, 3, padding='same', activation='selu')(x)
        x = dense_block(x, 16, 6)

        x = UpSampling2D()(x)
        x = Concatenate()([x, tier1])
        x = Conv2D(24, 3, padding='same', activation='selu')(x)
        x = dense_block(x, 12, 4)

        return x

    star_x = up_path(x)
    star = Conv2D(3, 1, padding='same', activation=None, name='star')(star_x)

    dash_x = up_path(x)
    dash = Conv2D(3, 1, padding='same', activation=None, name='dash')(dash_x)

    w_px_x = up_path(x)
    w_px = Conv2D(4, 1, padding='same', activation=None, name='wpx')(w_px_x)

    w_d_x = up_path(x)
    w_d = Conv2D(1, 1, padding='same', activation=None, name='wd')(w_d_x)

    seg_x = up_path(x)
    seg = Conv2D(1, 1, padding='same', activation='sigmoid')(seg_x)

    return star, dash, w_px, w_d, seg