scientific_comp_projects/CODE/[python]thesis_old_scripts/traitement_one_image.py

60 lines
2.2 KiB
Python
Raw Normal View History

2021-10-29 15:16:40 +02:00
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 12 14:13:34 2018
@author: Armando
"""
import ReadIM
from skimage import exposure
import cv2
import numpy as np
from functions_utile import draw_rectangle, image_correlation, test_homography, magnification
"""Traiter juste une image aves la calibration déjà faite :D"""
working_directory = "E:\\Donnees\\ArmandoBulle\\python_treatement\\PLIF_test\\"
#If you are working with DaViS here is where you write the name of the file
image = []
vbuff, vatts = ReadIM.extra.get_Buffer_andAttributeList(working_directory + 'donnees\\20180312_testeauXG25ppm_1\\B00350.im7')
v_array, vbuff = ReadIM.extra.buffer_as_array(vbuff)
img_rescaled = exposure.rescale_intensity(v_array)
img_rescaled = img_rescaled[0]
image = img_rescaled
image_left= image.copy()
image_left, rectangle_left = draw_rectangle(image_left)
#Obtain the image zone right
image_right= image.copy()
image_right, rectangle_right = draw_rectangle(image_right)
#Obtain the homography between both images
h , status = image_correlation(image_left,image_right)
image_right = cv2.warpPerspective(image_right, h, (image_left.shape[1],image_left.shape[0]))
image_ratio = np.divide(image_right,image_left)
for y in range(len(image_ratio)-1):
for x in range(len(image_ratio[0])-1):
if np.isinf(image_ratio[y][x]):
image_ratio[y][x] = 0
elif np.isnan(image_ratio[y][x]):
image_ratio[y][x] = 0
cv2.namedWindow("Final Source Image",cv2.WINDOW_NORMAL)
cv2.imshow("Final Source Image", image_ratio)
cv2.waitKey(0)
cv2.destroyAllWindows()
image_ratio = cv2.cvtColor(image_ratio, cv2.COLOR_GRAY2BGR)
cv2.imwrite(working_directory + 'Super_position_images_test.jpg', image_ratio)
cv2.imwrite(working_directory + 'Super_position_images_test.png', image_ratio)
cv2.imwrite(working_directory + 'Super_position_images_test.tiff', image_ratio)
rectangle_final = draw_rectangle(image_ratio)[1]
image_ratio =image_ratio[rectangle_final[0][1]:rectangle_final[1][1],rectangle_final[0][0]:rectangle_final[1][0]]
cv2.imwrite(working_directory + 'Super_position_images_test2.tiff', image_ratio)