I am trying to convert my TIFF image from 12 bits to 8 bits to be able to do a GLCM but it generates this problem:
AttributeError: 'module' object has no attribute 'unit12'
This is my code:
import numpy as np
import matplotlib.pyplot as plt
import gdal, gdalconst
import numpy as np
from skimage.feature import greycomatrix, greycoprops
import random
from scipy import *
def map_uint12_to_uint8(img, lower_bound=None, upper_bound=None):
filename = "recorte_rp.tif"
imgfile = gdal.Open(filename, gdalconst.GA_ReadOnly)
img = imgfile.ReadAsArray()
plt.imshow(img)
plt.imshow()
print(img)
print(img.shape)
if not(0 <= lower_bound < 2**12) and lower_bound is not None:
raise ValueError(
'"lower_bound" must be in the range [0, 4096]')
if not(0 <= upper_bound < 2**12) and upper_bound is not None:
raise ValueError('"upper_bound" must be in the range [0, 4096]')
if lower_bound is None:
lower_bound = np.min(img)
if upper_bound is None:
upper_bound = np.max(img)
if lower_bound >= upper_bound:
raise ValueError(
'"lower_bound" must be smaller than "upper_bound"')
lut = np.concatenate([
np.zeros(lower_bound, dtype=np.uint12),
np.linspace(0, 255, upper_bound - lower_bound).astype(np.uint12),
np.ones(2**12 - upper_bound, dtype=np.uint12) * 255
])
return lut[img].astype(np.uint8)
##
print(np.unit12)
#img = (np.random.random((100, 100)) * 2**12).astype(np.uint12)