def compute_mdsi(img1, img2, **kwargs): data_range = kwargs.pop("data_range", 1.0) use_grayscale = kwargs.pop("use_grayscale", False) # MDSI assumes 0-255 dynamic range for the input images # rescale both images to 0-255 maintaining the original dynamic range difference ratio img1 *= 255.0 / data_range img2 *= 255.0 / data_range if len(img1.shape) < 3: use_grayscale = True # MDSI takes 3-channel RGB images img1 = ensure3d(img1) img2 = ensure3d(img2) matlab_eng = mw.get_matlab_instance() out, err = mw.get_io_streams() path1, path2, tag = mw.imgs_to_unique_mat(img1, img2, extra_identifier='mdsi') mdsi = matlab_eng.MDSI_wrapper(path1, path2, tag, use_grayscale, stdout=out, stderr=err) mw.remove_matlab_unique_mat(path1, path2) return 1 - mdsi
def compute_hdr_vdp(img1, img2, **kwargs): global hdr_vdp_version matlab_eng = mw.get_matlab_instance() out, err = mw.get_io_streams() display_params = kwargs.pop('display_params', None) # 4 value array or tuple, see below for more info color_encoding = kwargs.pop('color_encoding', 'luminance') if color_encoding == 'luminance' and (len(img1.shape) > 2 or len(img2.shape) > 2): print("WARNING (HDR-VDP wrapper): using 'luminance' color_encoding requires single-channel Luminance (cd/m2) " "input but inputs with shapes {} and {} were provided. Will use 'sRGB-display' mode instead." .format(img1.shape, img2.shape)) color_encoding = 'sRGB-display' # TODO: maybe refactor this such that s, w, h come from the display model? if display_params is None: s = 21 # screen size in inches w = 1920; h = 1080 # screen resolution d = 0.5 # distance to the display else: s, w, h, d = display_params path1, path2, tag = mw.imgs_to_unique_mat(img1, img2, extra_identifier='hdrvdp') res = matlab_eng.hdrvdp_wrapper(path1, path2, tag, hdr_vdp_version, color_encoding, [s, w, h, d], stdout=out, stderr=err) # redirect prints to dummy I/O streams mw.remove_matlab_unique_mat(path1, path2) return (res["Q"] / 100.0) if hdr_vdp_version == '2.2.2' else res["Q"] / 10
def compute_fsim(img1, img2, **kwargs): data_range = kwargs.pop('data_range', 1.0) # FSIM assumes 0-255 dynamic range for the input images # rescale both images to 0-255 maintaining the original dynamic range difference ratio img1 *= 255.0 / data_range img2 *= 255.0 / data_range matlab_eng = mw.get_matlab_instance() out, err = mw.get_io_streams() path1, path2, tag = mw.imgs_to_unique_mat(img1, img2, extra_identifier='fsim') # Note: For grayscale images, the returned FSIM and FSIMc are the same fsim = matlab_eng.fsim_wrapper(path1, path2, tag, stdout=out, stderr=err) mw.remove_matlab_unique_mat(path1, path2) return fsim
def __compute_similarity(img1, img2, multiscale=True, use_python=False, **kwargs): """ Uses either the original SSIM implementation or its multi-scale variant :param img1: :param img2: :param multiscale: toggle between single- and multi- scale SSIM implementations (SSIM vs MSSIM) Note: this only applies when using MATLAB; only MSSIM is available for Python :param use_python: :param kwargs: :return: """ data_range = kwargs.pop('data_range', 1.0) if use_python: mat_range = 1.0 ref = (img1 * mat_range / data_range).astype(np.float) A = (img2 * mat_range / data_range).astype(np.float) return ssim_py(ref, A, multichannel=True, data_range=mat_range) else: mat_range = 255.0 # MATLAB version requires luminance inputs if len(img1.shape) == 3: img1 = rgb2lum(img1) img2 = rgb2lum(img2) ref = (img1 * mat_range / data_range).astype(np.int) A = (img2 * mat_range / data_range).astype(np.int) matlab_eng = mw.get_matlab_instance() out, err = mw.get_io_streams() path1, path2, tag = mw.imgs_to_unique_mat(A, ref, extra_identifier='ssim') ssim = matlab_eng.SSIM_wrapper(path1, path2, tag, multiscale, stdout=out, stderr=err) mw.remove_matlab_unique_mat(path1, path2) return ssim
def compute_vsi(img1, img2, **kwargs): data_range = kwargs.pop("data_range", 1.0) # VSI assumes 0-255 dynamic range for the input images # rescale both images to 0-255 maintaining the original dynamic range difference ratio img1 *= 255.0 / data_range img2 *= 255.0 / data_range # VSI takes 3-channel RGB images img1 = ensure3d(img1) img2 = ensure3d(img2) matlab_eng = mw.get_matlab_instance() out, err = mw.get_io_streams() path1, path2, tag = mw.imgs_to_unique_mat(img1, img2, extra_identifier='vsi') vsi = matlab_eng.vsi_wrapper(path1, path2, tag, stdout=out, stderr=err) mw.remove_matlab_unique_mat(path1, path2) return vsi