Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • samanost/sicom_image_analysis_project
  • gerayelk/sicom_image_analysis_project
  • jelassiy/sicom_image_analysis_project
  • chardoto/sicom_image_analysis_project
  • chaarim/sicom_image_analysis_project
  • domers/sicom_image_analysis_project
  • elmurrt/sicom_image_analysis_project
  • sadonest/sicom_image_analysis_project
  • kouddann/sicom_image_analysis_project
  • mirabitj/sicom-image-analysis-project-mirabito
  • plotj/sicom_image_analysis_project
  • torrem/sicom-image-analysis-project-maxime-torre
  • dzike/sicom_image_analysis_project
  • daip/sicom_image_analysis_project
  • casanovv/sicom_image_analysis_project
  • girmarti/sicom_image_analysis_project
  • lioretn/sicom_image_analysis_project
  • lemoinje/sicom_image_analysis_project
  • ouahmanf/sicom_image_analysis_project
  • vouilloa/sicom_image_analysis_project
  • diopb/sicom_image_analysis_project
  • davidale/sicom_image_analysis_project
  • enza/sicom_image_analysis_project
  • conversb/sicom_image_analysis_project
  • mullemat/sicom_image_analysis_project
25 results
Show changes
Showing
with 1887 additions and 0 deletions
from src.methods.brice_convers.dataHandler import DataHandler
from src.utils import psnr, ssim
from sklearn.metrics import f1_score, mean_squared_error
import numpy as np
class DataEvaluation:
def __init__(self, DataHandler: DataHandler):
DataEvaluation.DataHandler = DataHandler
def print_metrics(self, indexImage, method):
DataEvaluation.DataHandler.indexImageExists(indexImage)
img = DataEvaluation.DataHandler.load_image(indexImage)
res = DataEvaluation.DataHandler.get_reconstructed_image(indexImage, method)
ssimMetric = ssim(img, res)
psnrMetrc = psnr(img, res)
mse = mean_squared_error(img.flatten(), res.flatten())
mseRedPixels = mean_squared_error(img[:,:,0], res[:,:,0])
mseGreenPixels = mean_squared_error(img[:,:,1], res[:,:,1])
mseBluePixels = mean_squared_error(img[:,:,2], res[:,:,2])
miMetric = DataEvaluation.MI(img, res)
ccMetric = DataEvaluation.CC(img, res)
sadMetric = DataEvaluation.SAD(img, res)
lsMetric = DataEvaluation.LS(img, res)
print("[INFO] Metrics for image {}".format(indexImage))
print("#" * 30)
print(" SSIM: {:.6} ".format(ssimMetric))
print(" PSNR: {:.6} ".format(psnrMetrc))
print(" MSE : {:.3e} ".format(mse))
print(" MSE (R): {:.3e} ".format(mseRedPixels))
print(" MSE (G): {:.3e} ".format(mseGreenPixels))
print(" MSE (B): {:.3e} ".format(mseBluePixels))
print(" MI: {:.6} ".format(miMetric))
print(" CC: {:.6} ".format(ccMetric))
print(" SAD: {:.6} ".format(sadMetric))
print(" LS: {:.3e} ".format(lsMetric))
print("#" * 30)
#Mutual Information
def MI(img_mov, img_ref):
hgram, x_edges, y_edges = np.histogram2d(img_mov.ravel(), img_ref.ravel(), bins=20)
pxy = hgram / float(np.sum(hgram))
px = np.sum(pxy, axis=1) # marginal for x over y
py = np.sum(pxy, axis=0) # marginal for y over x
px_py = px[:, None] * py[None, :] # Broadcast to multiply marginals
# Now we can do the calculation using the pxy, px_py 2D arrays
nzs = pxy > 0 # Only non-zero pxy values contribute to the sum
return np.sum(pxy[nzs] * np.log(pxy[nzs] / px_py[nzs]))
# Cross Correlation
def CC(img_mov, img_ref):
# Vectorized versions of c,d,e
a = img_mov.astype('float64')
b = img_ref.astype('float64')
# Calculating mean values
AM = np.mean(a)
BM = np.mean(b)
c_vect = (a - AM) * (b - BM)
d_vect = (a - AM) ** 2
e_vect = (b - BM) ** 2
# Finally get r using those vectorized versions
r_out = np.sum(c_vect) / float(np.sqrt(np.sum(d_vect) * np.sum(e_vect)))
return r_out
#Sum of Absolute Differences
def SAD(img_mov, img_ref):
img1 = img_mov.astype('float64')
img2 = img_ref.astype('float64')
ab = np.abs(img1 - img2)
sav = np.sum(ab.ravel())
sav /= ab.ravel().shape[0]
return sav
#Sum of Least Squared Errors
def LS(img_mov, img_ref):
img1 = img_mov.astype('float64')
img2 = img_ref.astype('float64')
r = (img1 - img2)**2
sse = np.sum(r.ravel())
sse /= r.ravel().shape[0]
return sse
This diff is collapsed.
import src.methods.brice_convers.dataHandler as DataHandler
import src.methods.brice_convers.dataEvaluation as DataEvaluation
import time
WORKING_DIRECOTRY_PATH = "SICOM_Image_Analysis/sicom_image_analysis_project/"
DataHandler = DataHandler.DataHandler(WORKING_DIRECOTRY_PATH)
DataEvaluation = DataEvaluation.DataEvaluation(DataHandler)
def main(DataHandler):
IMAGE_PATH = WORKING_DIRECOTRY_PATH + "images/"
CFA_NAME = "quad_bayer"
METHOD = "menon"
startTime = time.time()
DataHandler.list_images(IMAGE_PATH)
DataHandler.print_list_images()
DataHandler.compute_CFA_images(CFA_NAME)
DataHandler.compute_reconstruction_images(METHOD, {"cfa": CFA_NAME})
DataHandler.plot_reconstructed_image(0, METHOD, {"cfa": CFA_NAME}, zoomSize="large")
DataEvaluation.print_metrics(0, METHOD)
endTime = time.time()
print("[INFO] Elapsed time: " + str(endTime - startTime) + "s")
print("[INFO] End")
if __name__ == "__main__":
main(DataHandler)
This diff is collapsed.
"""The main file for the reconstruction.
This file should NOT be modified except the body of the 'run_reconstruction' function.
Students can call their functions (declared in others files of src/methods/your_name).
"""
import numpy as np
import cv2
from src.forward_model import CFA
from src.methods.brice_convers.menon import demosaicing_CFA_Bayer_Menon2007
import src.methods.brice_convers.configuration as configuration
from src.methods.brice_convers.utilities import quad_bayer_to_bayer
def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:
"""Performs demosaicking on y.
Args:
y (np.ndarray): Mosaicked image to be reconstructed.
cfa (str): Name of the CFA. Can be bayer or quad_bayer.
Returns:
np.ndarray: Demosaicked image.
"""
input_shape = (y.shape[0], y.shape[1], 3)
op = CFA("bayer", input_shape)
if cfa == "quad_bayer":
y = quad_bayer_to_bayer(y)
op = CFA("bayer", y.shape)
reconstructed_image = demosaicing_CFA_Bayer_Menon2007(y, op.mask, configuration.PIXEL_PATTERN, configuration.REFINING_STEP)
if cfa == "quad_bayer":
return cv2.resize(reconstructed_image, input_shape[:2], interpolation=cv2.INTER_CUBIC)
else:
return reconstructed_image
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
File added
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
"""The main file for the reconstruction.
"""
import numpy as np
from src.forward_model import CFA
from src.methods.david_alexis.functions import bayer_gradient_interpolation, quad_gradient_interpolation
def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:
"""Performs demosaicking on y.
Args:
y (np.ndarray): Mosaicked image to be reconstructed.
cfa (str): Name of the CFA. Can be bayer or quad_bayer.
Returns:
np.ndarray: Demosaicked image.
"""
input_shape = (y.shape[0], y.shape[1], 3)
op = CFA(cfa, input_shape)
if cfa == "bayer":
res = bayer_gradient_interpolation(y, op)
else:
res = quad_gradient_interpolation(y, op)
return res
# Author: Alexis DAVID
This diff is collapsed.