I am trying a script that works with images in python.The first image was working and the second one did not work at all.
The script was
import matplotlib.pyplot as pltimport matplotlib.image as mpimgimport numpy as npimage = mpimg.imread('test.jpg')# Grab the x and y size and make a copy of the imageysize = image.shape[0]xsize = image.shape[1]color_select = np.copy(image)# Define color selection criteria###### MODIFY THESE VARIABLES TO MAKE YOUR COLOR SELECTIONred_threshold = 200green_threshold = 200blue_threshold = 200######rgb_threshold = [red_threshold, green_threshold, blue_threshold]# Do a boolean or with the "|" character to identify# pixels below the thresholdsthresholds = (image[:,:,0] < rgb_threshold[0]) \ | (image[:,:,1] < rgb_threshold[1]) \ | (image[:,:,2] < rgb_threshold[2])color_select[thresholds] = [0,0,0]plt.imshow(color_select)
Then I discovered the reason why the second image did not work
print("Red channel - Min:", np.min(image[:,:,0]), "Max:", np.max(image[:,:,0]))print("Green channel - Min:", np.min(image[:,:,1]), "Max:", np.max(image[:,:,1]))print("Blue channel - Min:", np.min(image[:,:,2]), "Max:", np.max(image[:,:,2]))
For the first image
Red channel - Min: 0 Max: 255Green channel - Min: 10 Max: 255Blue channel - Min: 0 Max: 255
For the second image that did not work
Red channel - Min: 0.0 Max: 1.0Green channel - Min: 0.0 Max: 1.0Blue channel - Min: 0.0 Max: 1.0
Can someone explain to me the basics of why some images use 0-255 and other 0.0 to 1.0?