Image processing in python

I am conducting a study processing images obtained from satellites. The problem I have is that when processing an image to correct it, instead of getting a variety of values in the resulting image, I only get the profile of it. Does anyone know what can be owed?

 -*- coding: cp1252 -*-
import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import math
import cv2

Parámetros banda TIRS
Ml=0.00033420
Al=0.10000
K1=774.8853
K2=1321.0789

bandaTIRSparque2=cv2.imread('bandaTIRS2.tif',-1)
BandaTIRSmodificada=np.array(bandaTIRSparque2[:],np.float)

for f in range(len(bandaTIRSparque2)):
      for c in range(len(bandaTIRSparque2[f])):
          if bandaTIRSparque2[f][c]!=0: 
                 BandaTIRSmodificada[f][c]=float((K2/np.log((K1/(Ml*bandaTIRSparque2[f][c]+Al))+1))*255)

cv2.imwrite('bandaTIRSmodificada.tif',BandaTIRSmodificada)

enter the description of the image here

 4
Author: kikocorreoso, 2016-08-20

1 answers

After looking at the image, it is an image in BN so it has no more channels.

Try the following and tell me if it solves the problem for you:

 -*- coding: cp1252 -*-
import numpy as np
import matplotlib.pyplot as plt
import cv2

# Parámetros banda TIRS
Ml = 0.00033420
Al = 0.10000
K1 = 774.8853
K2 = 1321.0789

# Uso el nombre de la imagen enlazada en los comentarios
orig = cv2.imread('bandaTIRparque1.tif',-1) 

# Creo una copia a la que le voy a modificar los datos diferentes a cero
nueva = orig.copy()

# Con numpy puedo hacer operaciones vectorizadas por lo que
# voy a modificar solo los píxeles que cumplan la condición valor != 0
indexes = orig != 0
nueva[indexes] = (K2 / np.log((K1 / (Ml * orig[indexes] + Al)) + 1)) * 255

cv2.imwrite('bandaTIRSmodificada.tif', nueva)

Several questions / comments.

  • if you use numpy you do not need to use math.
  • you import matplotlib.image but don't use it, at least in the piece of code you've pasted.
  • opencv would not be necessary for what you do since you can use matplotlib (plt.imread, plt.imsave).

The final image I'm left with is similar to the first one but escalated :

enter the description of the image here

 2
Author: kikocorreoso, 2016-09-02 10:42:21