grayscale enhancement - artificial vision


a. Write a function that allows you to highlight a specific range of grays in an image. The function must receive as input parameters: a grayscale image (uint8), parameter A and B that defines the range of values that the function will highlight. A and B must be positive and less than 255. Output image will be a black and white image; the white pixels will correspond to the pixels with values between A and B in the input image, and black pixels to all other pixels.

b. Select a color image, transform the image to grayscale and apply the range enhancement grays for the following values of A and B: [A, B] = {[20 240], [40 200], [80 180], [100 150], [120 135]}.

Hello again, this time is an artificial point of vision where you have to make a gray highlight. The question is that I understand very little. More or less I understand that you take an image and what is in black turns it white and white turns it black. I have searched on Google but it is not very understandable if someone knew how to explain to me I would appreciate it.

- The code we are implementing is this:

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.append('/media/basilio/ADATA UFD/VAI92/Code/')
import my_linealT as trans 

Im_g ='img2.jpg').convert('L')
Im_ga = np.array(Im_g)
a = np.array([1, 1, 1])
p1 = np.array([50, 125])
p2 = np.array([200, 225])
Im2 = trans.my_linealTrozos(Im_ga,a,p1,p2)


asked by Basilio Saldarriaga 27.08.2018 в 18:18

1 answer


When using PIL to access the pixels you must use the load () method, then iterate using the size attribute and if they are in the range, set them to 255 is the white color and 0 is the black color.

from PIL import Image
import matplotlib.pyplot as plt

def resaltar(imagen, rango):
    _from, _to = rango
    pixels = imagen.load()
    w, h = imagen.size
    for i in range(w):
        for j in range(h):
            pixels[i, j] = 0 if  _from <= pixels[i, j] <= _to else 255

image_gray = image_rgb.convert('L')
resaltar(image_gray, [0, 100])



answered by 27.08.2018 / 20:18