关于统计变换(CT/MCT/RMCT)算法的学习和实现
原文地址http://blog.sina.com.cn/s/blog_684c8d630100turx.html
| 123 | 127 | 129 |
| 126 | 128 | 129 |
| 127 | 131 | 130 |
| 1 | 1 | 0 |
| 1 | 0 | |
| 1 | 0 | 0 |
然后,把此窗口结果组成一个序列:11010100,以此二进制序列表示的值来代替原图像窗口中心点的像素。如此下去,等到窗口滑动完整幅图像,我们就得到原图像做统计变换(CT)之后的图像。
- % *************************************************************************
- % Title: Function-Census Transform of a given Image
- % Author: Siddhant Ahuja
- % Created: May 2008
- % Copyright Siddhant Ahuja, 2008
- % Inputs: Image (var: inputImage), Window size assuming square window (var:
- % windowSize) of 3x3 or 5x5 only.
- % Outputs: Census Tranformed Image (var: censusTransformedImage),
- % Time taken (var: timeTaken)
- % Example Usage of Function: [a,b]=funcCensusOneImage('Img.png', 3)
- % *************************************************************************
- function [censusTransformedImage, timeTaken] = funcCensusOneImage(inputImage, windowSize)
- % Grab the image information (metadata) using the function imfinfo
- try
- imageInfo = imfinfo(inputImage);
- % Since Census Transform is applied on a grayscale image, determine if the
- % input image is already in grayscale or color
- if(getfield(imageInfo,'ColorType')=='truecolor')
- % Read an image using imread function, convert from RGB color space to
- % grayscale using rgb2gray function and assign it to variable inputImage
- inputImage=rgb2gray(imread(inputImage));
- else if(getfield(imageInfo,'ColorType')=='grayscale')
- % If the image is already in grayscale, then just read it.
- inputImage=imread(inputImage);
- else
- error('The Color Type of Input Image is not acceptable. Acceptable color types are truecolor or grayscale.');
- end
- end
- catch
- inputImage = inputImage;
- end
- % Find the size (columns and rows) of the image and assign the rows to
- % variable nr, and columns to variable nc
- [nr,nc] = size(inputImage);
- % Check the size of window to see if it is an odd number.
- if (mod(windowSize,2)==0)
- error('The window size must be an odd number.');
- end
- if (windowSize==3)
- bits=uint8(0);
- % Create an image of size nr and nc, fill it with zeros and assign
- % it to variable censusTransformedImage of type uint8
- censusTransformedImage=uint8(zeros(nr,nc));
- else if (windowSize==5)
- bits=uint32(0);
- % Create an image of size nr and nc, fill it with zeros and assign
- % it to variable censusTransformedImage of type uint32
- censusTransformedImage=uint32(zeros(nr,nc));
- else
- error('The size of the window is not acceptable. Just 3x3 and 5x5 windows are acceptable.');
- end
- end
- % Initialize the timer to calculate the time consumed.
- tic;
- % Find out how many rows and columns are to the left/right/up/down of the
- % central pixel
- C= (windowSize-1)/2;
- for j=C+1:1:nc-C % Go through all the columns in an image (minus C at the borders)
- for i=C+1:1:nr-C % Go through all the rows in an image (minus C at the borders)
- census = 0; % Initialize default census to 0
- for a=-C:1:C % Within the square window, go through all the rows
- for b=-C:1:C % Within the square window, go through all the columns
- if (~(a==0 && b==0)) % Exclude the centre pixel from the calculation,原来是(C+1),现改为0
- census=bitshift(census,1); %Shift the bits to the left by 1
- % If the intensity of the neighboring pixel is less than
- % that of the central pixel, then add one to the bit
- % string
- if (inputImage(i+a,j+b) < inputImage(i,j))
- census=census+1;
- end
- end
- end
- end
- % Assign the census bit string value to the pixel in imgTemp
- censusTransformedImage(i,j) = census;
- end
- end
- % Stop the timer to calculate the time consumed.
- timeTaken=toc;
| 1 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 0 | 0 |
对应的二进制序列为:110100100。然后以此作为中心像素点的像素值,循环完毕之后便得到MCT之后的图像。需要注意的一点是,如果要使变换之后的图像得到显示,应该对像素值做一下归一化,使其在0——255之间。
- #include "stdafx.h"
- #include "MCT.h"
- #include "highgui.h"
- MCT::MCT()
- {
- window_size = 0;
- }
- MCT::~MCT()
- {
- }
- void MCT::ModifiedCensusTransform(IplImage *input_image, IplImage *mct_image, const int window_size, const int delta )
- {
- CvSize image_size = cvGetSize(input_image);
- int image_width = image_size.width;
- int image_height = image_size.height;
- IplImage *gray_image = cvCreateImage(cvGetSize(input_image), input_image->depth, 1);
- cvSetZero(gray_image);
- if(input_image->nChannels != 1)
- {
- cvCvtColor(input_image, gray_image, CV_RGB2GRAY);
- }
- else
- {
- cvCopy(input_image, gray_image);
- }
- IplImage *modified_image = NULL;
- switch (window_size)
- {
- case 3:
- modified_image = cvCreateImage(image_size, IPL_DEPTH_16U, 1);
- cvSetZero(modified_image);
- break;
- case 5:
- modified_image = cvCreateImage(image_size, IPL_DEPTH_32S, 1);
- cvSetZero(modified_image);
- break;
- default:
- printf("window size must be 3 or 5!\n");
- exit(EXIT_FAILURE);
- }
- CvMat window;
- for(int i = 0; i < image_height - window_size; i++)
- {
- for(int j = 0; j < image_width - window_size; j++)
- {
- unsigned long census = 0;
- CvRect roi = cvRect(j, i, window_size, window_size);
- cvGetSubRect(gray_image, &window, roi);
- CvScalar m = cvAvg(&window, NULL);
- for(int w = 0; w < window_size; w++)
- {
- for(int h = 0; h < window_size; h++)
- {
- census = census << 1; //左移1位
- double tempvalue = cvGetReal2D(&window, w, h);
- if(tempvalue < m.val[0] + delta)
- census += 1;
- }
- }
- cvSetReal2D(modified_image, i, j, census);
- }
- }
- //cvConvertScaleAbs(modified_image, mct_image, 1, 0);
- Normalize(modified_image, mct_image);
- cvReleaseImage(&gray_image);
- cvReleaseImage(&modified_image);
- }
- void MCT::Normalize(IplImage *mct_image, IplImage *nor_image)
- {
- double minv, maxv;
- cvMinMaxLoc(mct_image, &minv, &maxv);
- for (int i = 0; i < mct_image->height; i++)
- {
- for (int j = 0; j < mct_image->width; j++)
- {
- double tempv = cvGetReal2D(mct_image, i, j);
- tempv = (tempv - minv) / (maxv - minv) * 255;
- cvSetReal2D(nor_image, i, j, tempv);
- }
- }
- }
由于算法比较简单,所以没有写注释,应该比较容易理解。
关于统计变换(CT/MCT/RMCT)算法的学习和实现的更多相关文章
- 肺结节CT影像特征提取(二)——肺结节CT图像特征提取算法描述
摘自本人毕业论文<肺结节CT影像特征提取算法研究> 医学图像特征提取可以认为是基于图像内容提取必要特征,医学图像中需要什么特征基于研究需要,提取合适的特征.相对来说,医学图像特征提取要求更 ...
- NLP之统计句法分析(PCFG+CYK算法)
一.认识句法分析 首先,了解一下句法分析到底是什么意思?是做什么事情呢?顾名思义,感觉是学习英语时候讲的各种句法语法.没错!这里就是把句法分析过程交给计算机处理,让它分析一个句子的句法组成,然后更好理 ...
- 推荐一个算法编程学习中文社区-51NOD【算法分级,支持多语言,可在线编译】
最近偶尔发现一个算法编程学习的论坛,刚开始有点好奇,也只是注册了一下.最近有时间好好研究了一下,的确非常赞,所以推荐给大家.功能和介绍看下面介绍吧.首页的标题很给劲,很纯粹的Coding社区....虽 ...
- 算法导论学习---红黑树具体解释之插入(C语言实现)
前面我们学习二叉搜索树的时候发如今一些情况下其高度不是非常均匀,甚至有时候会退化成一条长链,所以我们引用一些"平衡"的二叉搜索树.红黑树就是一种"平衡"的二叉搜 ...
- 【树论 1】 prim算法的学习和使用
进阶版神犇可以看看本题解的姊妹篇 Kruskal算法的学习和使用 下面的内容是prim算法 但是最小生成树是什么呢? 标准定义如下:在边子集所构成的树中,不但包括了连通图里的所有顶点,且其所有边的权值 ...
- 毕业设计预习:SM3密码杂凑算法基础学习
SM3密码杂凑算法基础学习 术语与定义 1 比特串bit string 由0和1组成的二进制数字序列. 2 大端big-endian 数据在内存中的一种表示格式,规定左边为高有效位,右边为低有效位.数 ...
- 第八模块:算法&设计模式、企业应用 第1章 常用算法&设计模式学习
第八模块:算法&设计模式.企业应用 第1章 常用算法&设计模式学习
- leetcode 刷500道题,笔试/面试稳过吗?谈一谈这些年来算法的学习
想要学习算法.应付笔试或者应付面试手撕算法题,相信大部分人都会去刷 Leetcode,有读者问?如果我在 leetcode 坚持刷它个 500 道题,以后笔试/面试稳吗? 这里我说下我的个人看法,我认 ...
- 【中国象棋人机对战】引入了AI算法,学习低代码和高代码如何混编并互相调用
以低代码和高代码(原生JS代码)混编的方式引入了AI算法,学习如何使用表达式调用原生代码的.整个过程在众触低代码应用平台进行,适合高阶学员. AI智能级别演示 AI算法分三个等级,体现出来的智能水平不 ...
随机推荐
- java版复利计算器升级
github地址:https://github.com/iamcarson/Carson 伙伴:彭宏亮 学号:201406114148 与伙伴工作帅照: 本次升级的地方: 1.改善了界面显示,让界面整 ...
- jQuery的事件one
如果你只想你设计的对象只能让用户执行一次的话,可以使用jQuery的事件one()来实现. 演示一个,创建视图, 看看效果:
- 【C#】线程之Parallel
在一些常见的编程情形中,使用任务也许能提升性能.为了简化变成,静态类System.Threading.Tasks.Parallel封装了这些常见的情形,它内部使用Task对象. Parallel.Fo ...
- Java NIO中的读和写
一.概述 读和写是I/O的基本过程.从一个通道中读取只需创建一个缓冲区,然后让通道将数据读到这个缓冲区.写入的过程是创建一个缓冲区,用数据填充它,然后让通道用这些数据来执行写入操作. 二.从文件中读取 ...
- VS "15" 预览 5 中 VB 15 新增的功能
VS "15" 预览 5 给 VB 带来了更新.这次的更新内容有3个: * 值元组 ValueTuple这个功能能把一组计算结果成组返回.为了使用这个功能,我们要安装 System ...
- Discuz!X3解读之类引入机制及目录结构
实例: - /source/class/table/table_forum_faq.php - /source/class/model/model_forum_post.php - /source/p ...
- DP---Mahjong tree
HDU 5379 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenl ...
- 机器学习实战 - 读书笔记(11) - 使用Apriori算法进行关联分析
前言 最近在看Peter Harrington写的"机器学习实战",这是我的学习心得,这次是第11章 - 使用Apriori算法进行关联分析. 基本概念 关联分析(associat ...
- postgresql 9.6 rc1发布
postgresql 9.6 rc1发布了,意味着postgresql 9.6正式版将会越来越近了. 对于dss来说,postgresql远优于mysql,尤其是9.6新引入的并行执行,将大大提高性能 ...
- Postman的使用
在我们平时开发中,特别是需要与接口打交道时,无论是写接口还是用接口,拿到接口后肯定都得提前测试一下,这样的话就非常需要有一个比较给力的Http请求模拟工具,现在流行的这种工具也挺多的,像火狐浏览器插件 ...