Hot color detection in Python image

Asked

Viewed 285 times

1

I have a problem and I need your help.

I have a series of thermographic images, which I need to detect the hot spot (shown in the bar to the right of the image) in the area where the analysis is being made. In the case of these example images, the hot spot is in the focus of the aim, however, the goal is to imagine that I do not know where this point is and that the algorithm itself finds it, based on the right bar. I leave below one of these images as an example:

IR_1544.jpg

In this example, the sidebar indicates a temperature range between 33.2 and 97.7 °C. I would like to identify in the image where is the point of 97.7 °C. Initially I created a code where I read the BGR value in the highest point of the bar and I look for this combination in the rest of the image, this did not return me anything. Unconvinced, I created a code that identifies the RGB code throughout the bar and looks in the image, which also returned nothing, the code follows below:

# Find one of temperature bar colors in the image
import cv2
image_path = r"C:\Users\bruno\PycharmProjects\TCC\Imagens\IR_1544.jpg"

img = cv2.imread(image_path)
crop1 = img[69:171, 309:310]

for i in range(70, 172):
    crop = img[i-1:i, 309:310]
    num1, num2, num3 = cv2.split(crop)
    for i in range(0, crop.shape[0]):
        for j in range(0, crop.shape[1]):
            if img[i][j][0] == num1:
                if img[i][j][1] == num2:
                    if img[i][j][2] == num3:
                        print("I found")

cv2.imshow("img1", img)
cv2.imshow("img2", crop1)
cv2.waitKey(0)
cv2.destroyAllWindows()

I wonder if there’s another way I can identify these colors in the image. I thank all who can help!!

  • Have the image without this information from FLIR software?

  • I do not possess, at first the images I will have to process will always have this information :(

1 answer

1

Assuming you want to identify the 'highest temperature' in the image, and taking into account that the brightest point (pixel) in the image will be equal to the lightest point (pixel) in the bar:

  1. Convert to Gray Scale
  2. Apply cv2.Gaussianblur to smooth the pixels and remove noise. Here the secret is to adjust the kernel (35x35) according to your application. The bigger the kernel, the bigger the 'smoothing' area'.
  3. Calls cv2.minMaxLoc, which returns a tuple with the position of the most intense pixel in the image. [3]

Suggestion:

import cv2

image = cv2.imread("imagem.jpeg")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (35, 35), 0)
(_, _, _, maxIntense) = cv2.minMaxLoc(gray)

cv2.circle(image, maxIntense, 2, (0, 0, 0), 1)
cv2.rectangle(image, (maxIntense[0]-10, maxIntense[1]+10), (maxIntense[0]+10, maxIntense[1]-10), (0,0,0), 1)

cv2.imshow("Imagem", image)
cv2.waitKey(0)

I hope I’ve helped.

  • I really appreciate the tips. I had already managed to do, according to the answer given here: https://stackoverflow.com/questions/61599703/detecting-warm-colors-in-the-python-image. Anyway it matches your answer, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.