0
$\begingroup$

I am converting a pixel values to temp (values of a thermal image). But after conversion output image is not except able. Here is my code:

import cv2
import numpy as np
import matplotlib.pyplot as plt

#Thermal image
img = cv2.imread('IR2.bmp',0)

print(img)
pixel=np.asarray(img)

# storing in pixel array
for i in range(0,img.shape[0]):
   for j in range(0,img.shape[1]):
      print(pixel[i][j])

# converting pixel value to temperature values
r,c=(230,304)

arr = np.zeros([230,304])
for i in range(0,img.shape[0]):
   for j in range(0,img.shape[1]):
        arr[i][j] = 9.2+(pixel[i][j]/255)*26.2

print(arr)

# showing the converted image

cv2.imshow('converted',arr)

cv2.waitKey(0)
cv2.destroyAllWindows()

Input Thermal Image Output image

$\endgroup$
5
  • 1
    $\begingroup$ Your first for-loop "storing in pixel array" doesn't do anything, it just prints the array $\endgroup$
    – WBM
    Apr 21, 2021 at 7:37
  • $\begingroup$ Also see this stackoverflow.com/questions/15406075/… $\endgroup$
    – WBM
    Apr 21, 2021 at 7:42
  • $\begingroup$ Yes, for storing the pixel-i have done this just to check...But my major concern is the output image.I want the image with temp. values. $\endgroup$
    – Sayantan
    Apr 21, 2021 at 9:23
  • $\begingroup$ you could calculate it much faster in one line arr = 9.2 + (img/255) * 26.2 - without np.asarray, np.zeros, for-loops. But it gives the same values which are too small and they all looks like white color. $\endgroup$
    – furas
    May 3, 2021 at 9:36
  • $\begingroup$ Yes, that the problem..the final image is white...but it should not be...as the converted values are small,it should be in black shade.. $\endgroup$
    – Sayantan
    May 4, 2021 at 11:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.