<jupyter_start><jupyter_text>From Converted RJPEG To Temperature csv<jupyter_code>thermal_tab = genfromtxt('/Users/stouzani/Desktop/Unstructured_ML/Drone/Drone_Data_Capture/Veracruz/Thermal_preproc/temperature_DJI_0490_door.csv', delimiter=',')
#thermal_tab = genfromtxt('/Users/stouzani/Desktop/Unstructured_ML/Drone/Drone_Data_Capture/singapore/Thermal_preproc/IX-x1-00057_0278_0109_THM.csv', delimiter=',')

# thermal_tab = np.rot90(thermal_tab,3)
# exclude the bottom right column because of some noise
# thermal_tab = thermal_tab[0:147,0:485]
plt.figure()
plt.imshow(thermal_tab)
thermal_tab.shape
np.amax(thermal_tab)
np.amin(thermal_tab)
pixel_values = thermal_tab.reshape((-1, 1))
pixel_values = np.float32(pixel_values)
pixel_values.shape
pixel_values_croped = pixel_values.reshape((-1, 1))
pixel_values_croped.shape
pixel_values_croped
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2)
# number of clusters (K)
k = 8
_, labels, (centers) = cv2.kmeans(pixel_values_croped, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
centers
labels
# convert back to 8 bit values
centers = np.int8(centers)

# flatten the labels array
labels = labels.flatten()
centers
# convert all pixels to the color of the centroids
segmented_image_copped = centers[labels.flatten()]
segmented_image_copped.shape
segmented_image_copped.dtype
pixel_values.shape
segmented_image= segmented_image_copped
# reshape back to the original image dimension
segmented_image = segmented_image.reshape(thermal_tab.shape)
# show the image
plt.imshow(segmented_image)
plt.show()
from matplotlib import pyplot as plt

# x = np.random.randint(25,100,25)
# y = np.random.randint(175,255,25)
# z = np.hstack((x,y))
# z = z.reshape((50,1))
# z = np.float32(z)
plt.hist(segmented_image_copped,14,[35,46]),plt.show()

segmented_image_f = np.float32(segmented_image)
th = cv2.threshold(segmented_image_f,36,255,cv2.THRESH_BINARY)[1]
thresholded = th.astype(np.uint8)
thresholded = np.invert(thresholded)
plt.figure()
plt.imshow(thresholded)
thresholded = binary_dilation(thresholded, rectangle(1,5))
plt.figure()
plt.imshow(thresholded)
# thresholded = binary_erosion(thresholded, rectangle(5,1))
# plt.figure()
# plt.imshow(thresholded)
thresholded_2 = thresholded.astype(np.uint8)
contours, hierarchy = cv2.findContours(thresholded_2, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)<jupyter_output><empty_output><jupyter_text>Create RGB images<jupyter_code>thermal_im = 255*(thermal_tab - np.min(thermal_tab))/np.ptp(thermal_tab).astype(int)
thermal_im = cv2.cvtColor(thermal_im.astype(np.uint8),cv2.COLOR_GRAY2RGB)
plt.figure()
plt.imshow(thermal_im)
mask = np.zeros(thermal_im.shape, np.uint8)
borders_im = cv2.drawContours(mask, contours, -1, (255,0,0),3)
plt.figure()
plt.imshow(borders_im)<jupyter_output><empty_output><jupyter_text>superimpose images<jupyter_code>thermal_im_1 = Image.fromarray(thermal_im)
borders_im_1 = Image.fromarray(borders_im)
thermal_im_1 = thermal_im_1.convert("RGBA")
borders_im_1 = borders_im_1.convert("RGBA")
new_img = Image.blend(thermal_im_1, borders_im_1, 0.35)
new_img<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12315586914688903, 'fraction_numerical': 0.039448364336112894, 'mean_word_length': 8.146627565982405, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '375653', 'license': 'BSD-3-Clause-LBNL', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1218, 'n_words': 181, 'path': 'Thermal/Thermal_scripts/Thermal_segmentation_veracruz_only_door.ipynb', 'repo_name': 'LBNL-ETA/a3dbr', 'size': '3118'}