This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # @lc app=leetcode id=147 lang=python | |
| # | |
| # [147] Insertion Sort List | |
| # Category Difficulty Likes Dislikes | |
| # algorithms Medium (38.38%) 417 473 | |
| # Tags | |
| # Companies | |
| # Sort a linked list using insertion sort. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import skimage | |
| import cv2 | |
| from skimage.measure import compare_psnr, compare_ssim | |
| #YUV style to calc SSIM and PSNR | |
| def calc_psnr(im1, im2): | |
| im1_y = cv2.cvtColor(im1, cv2.COLOR_BGR2YCR_CB)[:, :, 0] | |
| im2_y = cv2.cvtColor(im2, cv2.COLOR_BGR2YCR_CB)[:, :, 0] | |
| return compare_psnr(im1_y, im2_y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| import math | |
| def purity(result, label): | |
| # 纯度 | |
| total_num = len(label) | |
| cluster_counter = collections.Counter(result) | |
| original_counter = collections.Counter(label) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // convert an OpenCV multi-channel matrix to Armadillo cube. A copy is made | |
| template <typename T, int NC> | |
| Cube<T> to_arma(const cv::Mat_<cv::Vec<T, NC>> &src) | |
| { | |
| vector<cv::Mat_<T>> channels; | |
| Cube<T> dst(src.cols, src.rows, NC); | |
| for (int c = 0; c < NC; ++c) | |
| channels.push_back({src.rows, src.cols, dst.slice(c).memptr()}); | |
| cv::split(src, channels); | |
| return dst; |