temp

求图像的信息熵

人盡茶涼 提交于 2020-01-08 23:36:38
  1948年,香农(Claude E. Shannon)提出了信息熵的概念,解决了对信息的量化度量问题。香农第一次用数学语言描述了概率于信息冗余度的关系。   信息的定义:     信息是确定性的增加。     信息是物质、能量、信息及其属性的标示。   所谓信息熵,是一个数学上颇为抽象的概念,在这里不妨把信息熵理解成某种特定信息的出现概率。根据Charles H. Bennett对Maxwell's Demon的重新解释,对信息的销毁是一个不可逆过程,所以销毁信息是符合热力学第二定律(熵增定律)的。一般而言,当一种信息出现概率更高的时候,表明它被传播得更广泛,或者说,被引用的程度更高。我们可以认为,从信息传播的角度来看,信息熵可以表示信息的价值。这样子我们就有一个衡量信息价值高低的标准,可以做出关于知识流通问题的更多推论。   【计算公式】     H(x)=E[I(xi)]=E[ log(2,1/p(xi)) ]=-∑p(xi)log(2,p(xi)) (i=1,2,..n) 1 double Entropy(Mat img) 2 { 3 //将输入的矩阵为图像 4 double temp[256]; 5 /*清零*/ 6 for(int i=0;i<256;i++) 7 { 8 temp[i] = 0.0; 9 } 10 /*计算每个像素的累积值*/ 11 for(int

java数据结构之常用排序算法

半城伤御伤魂 提交于 2020-01-08 15:48:35
冒泡排序 private void maopao(int arr[]) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } 选择排序 private void xuanze(int[] arr) { for (int i = 0; i < arr.length; i++) { int min = arr[i]; int x = -1; boolean b = false; for (int j = i; j < arr.length; j++) { if (arr[j] < min) { b = true; min = arr[j]; x = j; } } if (b) { int temp = arr[i]; arr[i] = min; arr[x] = temp; } } } 插入排序 1 private void charu(int[] arr2) { 2 int[] arr = new int[arr2.length]; 3 for (int i = 0; i < arr2

用PHP整理照片和视频文件

孤街浪徒 提交于 2020-01-08 13:32:35
  这个年代,谁要没有几张照片都对不起自己。从有相机到照的第一张照片起,留下了太多美好的记忆,记忆已成过往,回忆却希望永恒。奈何这些年照片太多,粗略看了下,将近70G,从这些个照片里找些回忆,翻找起来太麻烦,作为一个农场主的“老农民”,必须得想个办法整理下。梳理了自己的问题和需求如下:   花了2小时,整理了一段小代码,不到3分钟所有的照片和视频就规规矩矩,服服帖帖了。代码如下: <?php/** * 相册大翻转 * @param $process_dir 要处理的文件夹 * @param $tidy_dir 目标文件夹 * * @return bool */function read_all($process_dir,$tidy_dir){ $i=0; if(!is_dir($process_dir)) return false;//如果传过要处理的不是文件夹,则直接返回false $handle = opendir($process_dir); if ($handle) { while (($fl = readdir($handle)) !== false) { $temp = $process_dir . DIRECTORY_SEPARATOR . $fl; if (is_dir($temp) && $fl != '.' && $fl != '..') { read_all(

力扣208——实现 Trie (前缀树)

点点圈 提交于 2020-01-08 09:56:08
这道题主要是构造前缀树节点的数据结构,帮助解答问题。 原题 实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。 示例: Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // 返回 true trie.search("app"); // 返回 false trie.startsWith("app"); // 返回 true trie.insert("app"); trie.search("app"); // 返回 true 说明: 你可以假设所有的输入都是由小写字母 a-z 构成的。 保证所有输入均为非空字符串。 原题url: https://leetcode-cn.com/problems/implement-trie-prefix-tree/ 解题 前缀树的意义 我们用前缀树这种数据结构,主要是用在 在字符串数据集中搜索单词 的场景,但针对这种场景,我们也可以使用 平衡树 和 哈希表 ,而且哈希表可以在 O(1) 时间内寻找到键值。那为什么还要前缀树呢? 原因有3: 前缀树可以找到具有同意前缀的全部键值。 前缀树可以按词典枚举字符串的数据集。 前缀树在存储多个具有相同前缀的键时可以使用较少的空间,只需要 O(m) 的时间复杂度,其中 m

再次理解ARC引用计数

橙三吉。 提交于 2020-01-08 00:43:19
ARC代码: NSObject *p = [NSObject new]; 编译完 的MRC代码 : NSObject *temp = [NSObject new]; p = [temp retain]; [temp release]; ARC代码: __weak NSObject *p = [NSObject new]; 编译完的 MRC代码 : NSObject *temp = [NSObject new]; p = temp; [temp release]; 来源: https://www.cnblogs.com/yibinpan/p/12164315.html

PTA 7-10 迭代法求正数的平方根 (10分)

感情迁移 提交于 2020-01-07 22:56:44
利用迭代法求正数的平方根。x0=a/2; 输入格式: 要求,在一行输入实数a(a>0)和eps(eps>0)。 输出格式: 输出平方根,保留4位小数及迭代次数。 输入样例: 在这里给出一组输入。例如: 7.8 0.01 输出样例: 在这里给出相应的输出。例如: 2.7949 3 作者: 李志聪 单位: 哈尔滨师范大学 时间限制: 400 ms 内存限制: 64 MB 代码长度限制: 16 KB 1 import java.util.Scanner; 2 public class Main { 3 public static void main(String[] args) { 4 Scanner sc=new Scanner(System.in); 5 double a=sc.nextDouble(); 6 double eps=sc.nextDouble(); 7 int sum=1; 8 double temp=a/2,item; 9 item=0.5*temp+0.5*(a/temp); 10 while(Math.abs(item-temp)>=eps) { 11 temp=item; 12 item=0.5*temp+0.5*(a/temp); 13 sum++; 14 } 15 double k; 16 k=item*0.5+temp*0.5; 17 System

leetcode-bytedance-字符串的排列

♀尐吖头ヾ 提交于 2020-01-07 21:56:55
满脑子都是暴力法:结果就超时了 一开始这么想的,就生成所有的由s1的组合,然后依次去s2中寻找是否有匹配的。 class Solution : def checkInclusion ( self , s1 : str , s2 : str ) - > bool : all_str = self . get_all_str ( s1 ) for i in all_str : try : s2 . index ( i ) return True except : pass return False def get_all_str ( self , s ) : all_res = [ ] def fun ( s , res = "" ) : if len ( s ) == 0 : all_res . append ( res ) else : temp = s [ : ] for i in range ( len ( s ) ) : fun ( temp [ 0 : i ] + temp [ i + 1 : ] , res + s [ i ] ) fun ( s ) return list ( set ( all_res ) ) 超时,另外发现求字符串全部的排列可以使用交换位置法 def get_all_res ( str_ , num = 0 ) : if num == len (

Python模块学习——tempfile

北城余情 提交于 2020-01-07 08:26:19
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 主要有以下几个函数: tempfile.TemporaryFile 如何你的应用程序需要一个临时文件来存储数据,但不需要同其他程序共享,那么用TemporaryFile函数创建临时文件是最好的选择。其他的应用程序是无法找到或打开这个文件的,因为它并没有引用文件系统表。用这个函数创建的临时文件,关闭后会自动删除。 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import os import tempfile print 'Building a file name yourself:' filename = '/tmp/guess_my_name.%s.txt' % os.getpid() temp = open (filename, 'w+b' ) try : print 'temp:' , temp print 'temp.name:' , temp.name finally : temp.close() os.remove(filename) # Clean up the temporary file yourself print print 'TemporaryFile:' temp = tempfile.TemporaryFile()

node.js - check if file exists before creating temp file

守給你的承諾、 提交于 2020-01-05 09:33:55
问题 I want to create a temporary file/directory in node.js. To do this, I'm attempting a simple algorithm: Generate a file name based on pid, time, and random chars Check if file exists if yes: return to step 1 and repeat if not: create the file and return it Here's the problem: The node.js documentation for fs.exists explicitly states that fs.exists should not be used, and instead one should just use fs.open and catch a potential error: http://nodejs.org/docs/latest/api/fs.html#fs_fs_exists_path

Get TEMP folder

耗尽温柔 提交于 2020-01-04 02:52:17
问题 How do I get the path to the Temp folder from inside an InnoSetup Pascal script? Not the folder that the setup uses as it its temporary folder (which can be accessed using {tmp} ), but the actual user's Temp folder. 回答1: You can access the TEMP environment variable using the {%TEMP} constant. See here for details and a list of all constants. 来源: https://stackoverflow.com/questions/7318305/get-temp-folder