How to use the skimage.exposure.rescale_intensity function in skimage

To help you get started, we’ve selected a few skimage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CellProfiler / CellProfiler / tests / modules / test_thresholding.py View on Github external
module.global_operation.value = u"Manual"

    module.minimum.value = 0.2

    module.maximum.value = 0.8

    module.run(workspace)

    output = workspace.image_set.get_image("Thresholding")

    actual = output.pixel_data

    data = skimage.img_as_float(image.pixel_data)

    data = skimage.exposure.rescale_intensity(data)

    expected = numpy.zeros_like(data, dtype=numpy.bool)

    expected[data > 0.2] = True

    expected[data < 0.8] = False

    numpy.testing.assert_array_equal(expected, actual)
github FitMachineLearning / FitML / DeepQN / Main_Gym.py View on Github external
def preprocessing2(I):
  """ prepro 210x160x3 uint8 frame into 6400 (80x80) 1D float vector """

  I = I[35:195] # crop

  #print("x_t1",I.shape)
  x_t1 = skimage.color.rgb2gray(I)
  x_t1 = skimage.transform.resize(x_t1,(IMG_DIM,IMG_DIM))
  x_t1 = skimage.exposure.rescale_intensity(x_t1, out_range=(0, 255))
  #print("x_t1",x_t1.shape)
  #print("x_t1",x_t1)

  #x_t1 = x_t1.reshape(1, 1, x_t1.shape[0], x_t1.shape[1])
  #s_t1 = np.append(x_t1, s_t1[:, :3, :, :], axis=1)

  return x_t1 #flattens
github jmtyszka / mrgaze / mrgaze / improc.py View on Github external
Percentile scaling range

    Returns
    ----
    gray_rescale : numpy uint8 array
        Percentile rescaled image.
    """

    # Calculate intensity percentile range
    pA, pB = np.percentile(gray, perc_range)

    # Only rescale if limits are different
    if pB == pA:
        gray_rescale = gray
    else:
        gray_rescale = exposure.rescale_intensity(gray, in_range=(pA, pB))

    return gray_rescale
github gdubrg / POSEidon-Biwi / loadBIWI.py View on Github external
if stretch_img:
            img = stretch(img, 190)

        if equalize:
            cv2.equalizeHist(img.astype(np.uint8), img)

        if contrast:
            img = img.astype(np.float32)
            if channels > 1:
                for i_ch in range(channels):
                    img[..., i_ch] = exposure.rescale_intensity(img[...,i_ch].astype('float'), out_range=(0, 1))
            else:
                p2, p98 = np.percentile(img[img < 100], (2, 98))
                img = exposure.rescale_intensity(img.astype('float'), in_range=(p2, p98), out_range=(0,1))

        if standardize:
            img = img.astype(np.float32)
            if channels > 1:
                for i_ch in range(channels):
                    img[...,i_ch] = preprocessing.scale(img[...,i_ch].astype('float'))
            else:
                img = preprocessing.scale(img.astype('float'))

        img = img.astype(np.float32)


        if img.shape[1] != img_cols or img.shape[0] != img_rows:
            img = cv2.resize(img, (img_cols,img_rows))
github gdubrg / POSEidon-Biwi / loadBIWI.py View on Github external
img[img > 255] = 255


        if stretch_img:
            img = stretch(img, 190)

        if equalize:
            cv2.equalizeHist(img.astype(np.uint8), img)

        if contrast:
            img = img.astype(np.float32)
            if channels > 1:
                for i_ch in range(channels):
                    img[..., i_ch] = exposure.rescale_intensity(img[..., i_ch].astype('float'), out_range=(0, 1))
            else:
                img = exposure.rescale_intensity(img.astype('float'), out_range=(0, 1))

        if standardize:
            img = img.astype(np.float32)
            if channels > 1:
                for i_ch in range(channels):
                    img[..., i_ch] = preprocessing.scale(img[..., i_ch].astype('float'))
            else:
                img = preprocessing.scale(img.astype('float'))

        img = img.astype(np.float32)

        if img.shape[1] != img_cols or img.shape[0] != img_rows:
            img = cv2.resize(img, (img_cols, img_rows))

        if channels == 1:
            img = np.expand_dims(img, axis=0)
github ParkHeeseung / Traffic-Sign-Recognition-with-Machine-LearningAndOpenCV / HOG + KNN / RecognizeTrafficSign.py View on Github external
# cv2.imshow("reuslt", logo)
	# logo = logo[50:350, 50:350]

	# extract Histogram of Oriented Gradients from the test image and
	# predict the make of the car
	(H, hogImage) = feature.hog(logo, orientations=8, pixels_per_cell=(8, 8),
		cells_per_block=(2, 2), transform_sqrt=True, block_norm="L2", visualise=True)
	pred = model.predict(H.reshape(1, -1))[0]
	pred1 = model.predict_proba(H.reshape(1, -1))[0]
	print(pred1)
	#print(dir(pred))
	# pred = model.predict(H)


	# visualize the HOG image
	hogImage = exposure.rescale_intensity(hogImage, out_range=(0, 255))
	hogImage = hogImage.astype("uint8")
	# cv2.imshow("HOG Image #{}".format(i + 1), hogImage)

	# draw the prediction on the test image and display it
	cv2.putText(image, pred.title(), (10, 35), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
		(0, 255, 0), 3)
	cv2.imshow("Test Image #{}".format(i + 1), image)
	cv2.waitKey(0)
github earthlab / earthpy / earthpy / plot.py View on Github external
arr: numpy array
        N-dimensional array in rasterio band order (bands, rows, columns)
    str_clip: int
        The % of clip to apply to the stretch. Default = 2 (2 and 98)

    Returns
    ----------
    arr: numpy array with values stretched to the specified clip %

    """
    s_min = str_clip
    s_max = 100 - str_clip
    arr_rescaled = np.zeros_like(arr)
    for ii, band in enumerate(arr):
        lower, upper = np.percentile(band, (s_min, s_max))
        arr_rescaled[ii] = exposure.rescale_intensity(
            band, in_range=(lower, upper)
        )
    return arr_rescaled.copy()
github Xiaomi2008 / active_object_localization_RL / deep_qlean.py View on Github external
raise NameError(args.data  + ' :  No such env !' )
    object_loc_env.action_alpha=ACTION_ALPHA

    model_file =get_model_file(args)
    # store the previous observations in replay memory
    D =deque()

    # get the first state by doing nothing and preprocess the image to 80x80x4
    # do_nothing = np.zeros(ACTIONS)
    # do_nothing[0] = 1
    # sipdb.set_trace()
    x_t, r_0, terminal = object_loc_env.localization_step(0)

    # x_t = skimage.color.rgb2gray(x_t)
    x_t = skimage.transform.resize(x_t,(img_rows,img_rows))
    x_t = skimage.exposure.rescale_intensity(x_t,out_range=(0,255))
    s_t=x_t
    action_history_st =[np.zeros([ACTIONS+1]) for i in range(ACTION_HISTORY)]
    action_history_st_1 =[np.zeros([ACTIONS+1]) for i in range(ACTION_HISTORY)]
    # ipdb.set_trace()
    # s_t = np.stack((x_t, x_t, x_t, x_t), axis=2)
    #print (s_t.shape)

    #In Keras, need to reshape
    channels = 1 if len(s_t.shape) <=2 else s_t.shape[2]
    # channels =channels*5 if args.multi_warp else channels

    s_t = s_t.reshape(1, s_t.shape[0], s_t.shape[1], channels)  #1*80*80*1 or 3
    s_at=np.array(action_history_st)
    s_at=np.reshape(s_at,(1,-1))
    S_Ts=[s_t,s_at]
    # ipdb.set_trace()
github shalabhsingh / A3C_Keras_FlappyBird / train_network.py View on Github external
def preprocess(image):
	image = skimage.color.rgb2gray(image)
	image = skimage.transform.resize(image, (IMAGE_ROWS, IMAGE_COLS), mode = 'constant')	
	image = skimage.exposure.rescale_intensity(image, out_range=(0,255))
	image = image.reshape(1, image.shape[0], image.shape[1], 1)
	return image
github jgrss / spfeas / spfeas / spfunctions.py View on Github external
def scale_rgb(layers, min_max, lidx):

    layers_c = np.empty(layers.shape, dtype='float32')

    # Rescale and blur.
    for li in range(0, 3):

        layer = layers[li]

        layer = np.float32(rescale_intensity(layer,
                                             in_range=(min_max[li][0],
                                                       min_max[li][1]),
                                             out_range=(0, 1)))

        layers_c[lidx[li]] = rescale_intensity(cv2.GaussianBlur(layer,
                                                                ksize=(3, 3),
                                                                sigmaX=3),
                                               in_range=(0, 1),
                                               out_range=(-1, 1))

    return layers_c