I5-ds 2dc6420iw ap能玩吃鸡吗 跪求悬赏分!!!!!

翻译自如下链接的java版本。
http://blog.csdn.net/jia20003/article/details/6919845
http://download.csdn.net/detail/seafit/9504306
分不够了,暂时收取一分吧。
用的时候:
CImageScaler* imageScaler = new CImageScaler();
char* newData = (char*)imageScaler-&Scale((int*)m_imageData,m_width,m_height,newWidth,newHeight);
数据格式是ARGB,看源代码应该只要是32位像素即可,顺序应该不限定。
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:87516次
积分:1466
积分:1466
排名:千里之外
原创:49篇
转载:41篇
评论:26条
(6)(4)(1)(3)(2)(4)(7)(1)(1)(6)(1)(1)(1)(3)(3)(1)(2)(5)(5)(2)(2)(1)(2)(1)(1)(1)(1)(1)(1)(1)(12)(7)(2)(1)java代码怎么实现图像Lanczos采样放大缩小算法
下面给大家介绍java代码怎么实现图像Lanczos采样放大缩小算法,希望能给大家提供帮助。
一:什么是Lanczos采样
参见这里:http://en.wikipedia.org/wiki/Lanczos_resampling
二:大致算法流程
三:算法运行结果
1.向下采样, 生成缩略图, 左边为原图,右边为缩略图
向上采样,生成放大图像时效果:
算法源代码:
package&com.gloomyfish.zoom.&& &&& &import&java.awt.image.BufferedI&& &import&java.awt.image.ColorM&& &&& &import&com.gloomyfish.filter.study.AbstractBufferedImageOp;&& &&& &public&class&LanczosScaleFilter&extends&AbstractBufferedImageOp&{&& &&&&&//&lanczos_size&& &&&&&private&float&lanczosS&& &&&&&private&float&destW&& &&&&&&& &&&&&public&LanczosScaleFilter()&& &&&&&{&& &&&&&&&&&lanczosSize&=&3;&& &&&&&&&&&destWidth&=&100;&& &&&&&}&& &&& &&&&&public&LanczosScaleFilter(float&lobes,&int&width)&{&& &&&&&&&&&this.lanczosSize&=&lobes;&& &&&&&&&&&this.destWidth&=&width;&& &&&&&}&& &&& &&&&&public&void&setLanczosSize(float&size)&{&& &&&&&&&&&this.lanczosSize&=&size;&& &&&&&}&& &&& &&&&&public&void&setDestWidth(float&destWidth)&{&& &&&&&&&&&this.destWidth&=&destW&& &&&&&}&& &&& &&&&&@Override&& &&&&&public&BufferedImage&filter(BufferedImage&src,&BufferedImage&dest)&{&& &&&&&&&&&int&width&=&src.getWidth();&& &&&&&&&&&int&height&=&src.getHeight();&& &&&&&&&&&float&ratio&=&width&/&this.destW&& &&&&&&&&&float&rcp_ratio&=&2.0f&/&&& &&&&&&&&&float&range2&=&(float)&Math.ceil(ratio&*&lanczosSize&/&2);&& &&&&&&&&&&& &&&&&&&&&//&destination&image&& &&&&&&&&&int&dh&=&(int)(height&*&(this.destWidth/width));&& &&&&&&&&&int&dw&=&(int)this.destW&& &&& &&&&&&&&&if&(dest&==&null)&{&& &&&&&&&&&&&&&ColorModel&cMD&=&src.getColorModel();&& &&&&&&&&&&&&&dest&=&new&BufferedImage(src.getColorModel(),&cMD.createCompatibleWritableRaster(dw,&dh),&cMD.isAlphaPremultiplied(),&null);&& &&&&&&&&&}&& &&& &&&&&&&&&int[]&inPixels&=&new&int[width&*&height];&& &&&&&&&&&int[]&outPixels&=&new&int[dw&*&dh];&& &&&&&&&&&&& &&&&&&&&&getRGB(src,&0,&0,&width,&height,&inPixels);&& &&&&&&&&&int&index&=&0;&& &&&&&&&&&float&fcy&=&0,&icy&=&0,&fcx&=&0,&icx&=&0;&& &&&&&&&&&for&(int&row&=&0;&row&&;&row++)&{&& &&&&&&&&&&&&&int&ta&=&0,&tr&=&0,&tg&=&0,&tb&=&0;&& &&&&&&&&&&&&&fcy&=&(row&+&0.5f)&*&&& &&&&&&&&&&&&&icy&=&(float)&Math.floor(fcy);&& &&&&&&&&&&&&&for&(int&col&=&0;&col&&;&col++)&{&& &&&&&&&&&&&&&&&&&fcx&=&(col&+&0.5f)&*&&& &&&&&&&&&&&&&&&&&icx&=&(float)&Math.floor(fcx);&& &&& &&&&&&&&&&&&&&&&&float&sumred&=&0,&sumgreen&=&0,&sumblue&=&0;&& &&&&&&&&&&&&&&&&&float&totalWeight&=&0;&& &&&&&&&&&&&&&&&&&for&(int&subcol&=&(int)&(icx&-&range2);&subcol&=&icx&+&range2;&subcol++)&{&& &&&&&&&&&&&&&&&&&&&&&if&(subcol&&&||&subcol&=&width)&& &&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&int&ncol&=&(int)&Math.floor(1000&*&Math.abs(subcol&-&fcx));&& &&& &&&&&&&&&&&&&&&&&&&&&for&(int&subrow&=&(int)&(icy&-&range2);&subrow&=&icy&+&range2;&subrow++)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&if&(subrow&&&||&subrow&=&height)&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&int&nrow&=&(int)&Math.floor(1000&*&Math.abs(subrow&-&fcy));&& &&&&&&&&&&&&&&&&&&&&&&&&&float&weight&=&(float)&getLanczosFactor(Math.sqrt(Math.pow(ncol&*&rcp_ratio,&2)&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&Math.pow(nrow&*&rcp_ratio,&2))&/&1000);&& &&&&&&&&&&&&&&&&&&&&&&&&&if&(weight&&0)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&index&=&(subrow&*&width&+&subcol);&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&tr&=&(inPixels[index]&&16)&&&0&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&tg&=&(inPixels[index]&&8)&&&0&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&tb&=&inPixels[index]&&&0&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&totalWeight&+=&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&sumred&+=&weight&*&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&sumgreen&+=&weight&*&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&sumblue&+=&weight&*&&& &&&&&&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&index&=&row&*&dw&+&&& &&&&&&&&&&&&&&&&&tr&=&(int)&(sumred&/&totalWeight);&& &&&&&&&&&&&&&&&&&tg&=&(int)&(sumgreen&/&totalWeight);&& &&&&&&&&&&&&&&&&&tb&=&(int)&(sumblue&/&totalWeight);&& &&&&&&&&&&&&&&&&&outPixels[index]&=&(255&&)&|&(clamp(tr)&&)&|&(clamp(tg)&&)&|&clamp(tb);&& &&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&//&clear&for&next&pixel&& &&&&&&&&&&&&&&&&&sumred&=&0;&& &&&&&&&&&&&&&&&&&sumgreen&=&0;&& &&&&&&&&&&&&&&&&&sumblue&=&0;&& &&&&&&&&&&&&&&&&&totalWeight&=&0;&& &&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&&&&&setRGB(dest,&0,&0,&dw,&dh,&outPixels);&& &&&&&&&&&return&&& &&&&&}&& &&&&&&& &&&&&public&static&int&clamp(int&v)&& &&&&&{&& &&&&&&&&&return&v&&255&?&255&:&(v&&&?&0&:&v);&& &&&&&}&& &&& &&&&&private&double&getLanczosFactor(double&distance)&{&& &&&&&&&&&if&(distance&&lanczosSize)&& &&&&&&&&&&&&&return&0;&& &&&&&&&&&distance&*=&Math.PI;&& &&&&&&&&&if&(Math.abs(distance)&&)&& &&&&&&&&&&&&&return&1;&& &&&&&&&&&double&xx&=&distance&/&lanczosS&& &&&&&&&&&return&Math.sin(distance)&*&Math.sin(xx)&/&distance&/&&& &&&&&}&& &&& &}&&&
五:窗口大小对结果的影响
如果是向下采样生成缩略图的话, 窗口大小设置为3就已经非常清楚了
如果向上采样要放大图像的话, 窗口大小设置要大于6才能获得较好结果,推荐使用窗口大小为8.
(责任编辑:6g下载网)
------分隔线----------------------------
本站所有软件和资料均为软件作者提供和网友推荐收集整理而来,仅供学习和研究使用。如有侵权,请联系站长QQ:
Copyright (C) g下载网().All Rights Reserved
黔ICP备号-2君,已阅读到文档的结尾了呢~~
双线性插值算法及其并行实现,双线性插值算法,双线性内插值算法,双线性插值算法原理,java 双线性插值算法,图像双线性插值算法,双线性插值算法优化,线性插值算法,三线性插值算法,三维线性插值算法
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
双线性插值算法及其并行实现
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口java代码怎么实现图像霍夫变换圆检测算法
下面给大家介绍java代码怎么实现图像霍夫变换圆检测算法,希望能给大家提供帮助。
我再写一篇,介绍霍夫变换圆检测算法,同时也尽量的加上详细的注释,介绍代码结构.让更多的人能够读懂与理解.
一:霍夫变换检测圆的数学原理
根据极坐标,圆上任意一点的坐标可以表示为如上形式, 所以对于任意一个圆, 假设中心像素点p(x0, y0)像素点已知, 圆半径已知,则旋转360由极坐标方程可以得到每个点上得坐标同样,如果只是知道图像上像素点, 圆半径,旋转360&则中心点处的坐标值必定最强.这正是霍夫变换检测圆的数学原理.
二:算法流程
该算法大致可以分为以下几个步骤
三:运行效果
图像从空间坐标变换到极坐标效果, 最亮一点为圆心.
图像从极坐标变换回到空间坐标,检测结果显示:
四:关键代码解析
个人觉得这次注释已经是非常的详细啦,而且我写的还是中文注释
/**& &&*&霍夫变换处理&-&检测半径大小符合的圆的个数& &&*&1.&将图像像素从2D空间坐标转换到极坐标空间& &&*&2.&在极坐标空间中归一化各个点强度,使之在0?255之间& &&*&3.&根据极坐标的R值与输入参数(圆的半径)相等,寻找2D空间的像素点& &&*&4.&对找出的空间像素点赋予结果颜色(红色)& &&*&5.&返回结果2D空间像素集合& &&*&@return&int&[]& &&*/&& &public&int[]&process()&{&& &&& &&&&&//&对于圆的极坐标变换来说,我们需要360度的空间梯度叠加值&& &&&&&acc&=&new&int[width&*&height];&& &&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&acc[y&*&width&+&x]&=&0;&& &&&&&&&&&}&& &&&&&}&& &&&&&int&x0,&y0;&& &&&&&double&t;&& &&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&& &&&&&&&&&&&&&if&((input[y&*&width&+&x]&&&0xff)&==&255)&{&& &&& &&&&&&&&&&&&&&&&&for&(int&theta&=&0;&theta&&;&theta++)&{&& &&&&&&&&&&&&&&&&&&&&&t&=&(theta&*&3.)&/&180;&//&角度值0&~&2*PI&& &&&&&&&&&&&&&&&&&&&&&x0&=&(int)&Math.round(x&-&r&*&Math.cos(t));&& &&&&&&&&&&&&&&&&&&&&&y0&=&(int)&Math.round(y&-&r&*&Math.sin(t));&& &&&&&&&&&&&&&&&&&&&&&if&(x0&&&&&&x0&&0&&&&y0&&&&&&y0&&0)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&acc[x0&+&(y0&*&width)]&+=&1;&& &&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&}&& &&& &&&&&//&now&normalise&to&255&and&put&in&format&for&a&pixel&array&& &&&&&int&max&=&0;&& &&& &&&&&//&Find&max&acc&value&& &&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&& &&&&&&&&&&&&&if&(acc[x&+&(y&*&width)]&&max)&{&& &&&&&&&&&&&&&&&&&max&=&acc[x&+&(y&*&width)];&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&}&& &&& &&&&&//&根据最大值,实现极坐标空间的灰度值归一化处理&& &&&&&int&&& &&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&&&&&value&=&(int)&(((double)&acc[x&+&(y&*&width)]&/&(double)&max)&*&255.0);&& &&&&&&&&&&&&&acc[x&+&(y&*&width)]&=&0xff000000&|&(value&&&|&value&&&|&value);&& &&&&&&&&&}&& &&&&&}&& &&&&&&& &&&&&//&绘制发现的圆&& &&&&&findMaxima();&& &&&&&System.out.println(&done&);&& &&&&&return&&& &}&&&
完整的算法源代码, 已经全部的加上注释
package&com.gloomyfish.image.transform.&& &/***& &&*&& &&*&传入的图像为二值图像,背景为黑色,目标前景颜色为为白色& &&*&@author&gloomyfish& &&*&& &&*/&& &public&class&CircleHough&{&& &&& &&&&&private&int[]&&& &&&&&private&int[]&&& &&&&&private&int&&& &&&&&private&int&&& &&&&&private&int[]&&& &&&&&private&int&accSize&=&1;&& &&&&&private&int[]&&& &&&&&private&int&r;&//&圆周的半径大小&& &&& &&&&&public&CircleHough()&{&& &&&&&&&&&System.out.println(&Hough&Circle&Detection...&);&& &&&&&}&& &&& &&&&&public&void&init(int[]&inputIn,&int&widthIn,&int&heightIn,&int&radius)&{&& &&&&&&&&&r&=&radius;&& &&&&&&&&&width&=&widthIn;&& &&&&&&&&&height&=&heightIn;&& &&&&&&&&&input&=&new&int[width&*&height];&& &&&&&&&&&output&=&new&int[width&*&height];&& &&&&&&&&&input&=&inputIn;&& &&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&&&&&output[x&+&(width&*&y)]&=&0xff000000;&//默认图像背景颜色为黑色&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&}&& &&& &&&&&public&void&setCircles(int&circles)&{&& &&&&&&&&&accSize&=&circles;&//&检测的个数&& &&&&&}&& &&&&&&& &&&&&/**& &&&&&&*&霍夫变换处理&-&检测半径大小符合的圆的个数& &&&&&&*&1.&将图像像素从2D空间坐标转换到极坐标空间& &&&&&&*&2.&在极坐标空间中归一化各个点强度,使之在0?255之间& &&&&&&*&3.&根据极坐标的R值与输入参数(圆的半径)相等,寻找2D空间的像素点& &&&&&&*&4.&对找出的空间像素点赋予结果颜色(红色)& &&&&&&*&5.&返回结果2D空间像素集合& &&&&&&*&@return&int&[]& &&&&&&*/&& &&&&&public&int[]&process()&{&& &&& &&&&&&&&&//&对于圆的极坐标变换来说,我们需要360度的空间梯度叠加值&& &&&&&&&&&acc&=&new&int[width&*&height];&& &&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&&&&&acc[y&*&width&+&x]&=&0;&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&&&&&int&x0,&y0;&& &&&&&&&&&double&t;&& &&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&& &&&&&&&&&&&&&&&&&if&((input[y&*&width&+&x]&&&0xff)&==&255)&{&& &&& &&&&&&&&&&&&&&&&&&&&&for&(int&theta&=&0;&theta&&;&theta++)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&t&=&(theta&*&3.)&/&180;&//&角度值0&~&2*PI&& &&&&&&&&&&&&&&&&&&&&&&&&&x0&=&(int)&Math.round(x&-&r&*&Math.cos(t));&& &&&&&&&&&&&&&&&&&&&&&&&&&y0&=&(int)&Math.round(y&-&r&*&Math.sin(t));&& &&&&&&&&&&&&&&&&&&&&&&&&&if&(x0&&&&&&x0&&0&&&&y0&&&&&&y0&&0)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&acc[x0&+&(y0&*&width)]&+=&1;&& &&&&&&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&& &&&&&&&&&//&now&normalise&to&255&and&put&in&format&for&a&pixel&array&& &&&&&&&&&int&max&=&0;&& &&& &&&&&&&&&//&Find&max&acc&value&& &&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&& &&&&&&&&&&&&&&&&&if&(acc[x&+&(y&*&width)]&&max)&{&& &&&&&&&&&&&&&&&&&&&&&max&=&acc[x&+&(y&*&width)];&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&& &&&&&&&&&//&根据最大值,实现极坐标空间的灰度值归一化处理&& &&&&&&&&&int&&& &&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&&&&&&&&&value&=&(int)&(((double)&acc[x&+&(y&*&width)]&/&(double)&max)&*&255.0);&& &&&&&&&&&&&&&&&&&acc[x&+&(y&*&width)]&=&0xff000000&|&(value&&&|&value&&&|&value);&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&&&&&&&&&& &&&&&&&&&//&绘制发现的圆&& &&&&&&&&&findMaxima();&& &&&&&&&&&System.out.println(&done&);&& &&&&&&&&&return&&& &&&&&}&& &&& &&&&&private&int[]&findMaxima()&{&& &&&&&&&&&results&=&new&int[accSize&*&3];&& &&&&&&&&&int[]&output&=&new&int[width&*&height];&& &&&&&&&&&&& &&&&&&&&&//&获取最大的前accSize个值&& &&&&&&&&&for&(int&x&=&0;&x&&;&x++)&{&& &&&&&&&&&&&&&for&(int&y&=&0;&y&&;&y++)&{&& &&&&&&&&&&&&&&&&&int&value&=&(acc[x&+&(y&*&width)]&&&0xff);&& &&& &&&&&&&&&&&&&&&&&//&if&its&higher&than&lowest&value&add&it&and&then&sort&& &&&&&&&&&&&&&&&&&if&(value&&results[(accSize&-&1)&*&3])&{&& &&& &&&&&&&&&&&&&&&&&&&&&//&add&to&bottom&of&array&& &&&&&&&&&&&&&&&&&&&&&results[(accSize&-&1)&*&3]&=&&//像素值&& &&&&&&&&&&&&&&&&&&&&&results[(accSize&-&1)&*&3&+&1]&=&x;&//&坐标X&& &&&&&&&&&&&&&&&&&&&&&results[(accSize&-&1)&*&3&+&2]&=&y;&//&坐标Y&& &&& &&&&&&&&&&&&&&&&&&&&&//&shift&up&until&its&in&right&place&& &&&&&&&&&&&&&&&&&&&&&int&i&=&(accSize&-&2)&*&3;&& &&&&&&&&&&&&&&&&&&&&&while&((i&=&0)&&&&(results[i&+&3]&&results[i]))&{&& &&&&&&&&&&&&&&&&&&&&&&&&&for&(int&j&=&0;&j&&;&j++)&{&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&int&temp&=&results[i&+&j];&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&results[i&+&j]&=&results[i&+&3&+&j];&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&results[i&+&3&+&j]&=&&& &&&&&&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&&&&&&&&&ii&=&i&-&3;&& &&&&&&&&&&&&&&&&&&&&&&&&&if&(i&&)&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&}&& &&&&&&&&&}&& &&& &&&&&&&&&//&根据找到的半径R,中心点像素坐标p(x,&y),绘制圆在原图像上&& &&&&&&&&&System.out.println(&top&&&+&accSize&+&&&matches:&);&& &&&&&&&&&for&(int&i&=&accSize&-&1;&i&=&0;&i--)&{&& &&&&&&&&&&&&&drawCircle(results[i&*&3],&results[i&*&3&+&1],&results[i&*&3&+&2]);&& &&&&&&&&&}&& &&&&&&&&&return&&& &&&&&}&& &&& &&&&&private&void&setPixel(int&value,&int&xPos,&int&yPos)&{&& &&&&&&&&&///&output[(yPos&*&width)&+&xPos]&=&0xff000000&|&(value&&&|&value&&&|&value);&& &&&&&&&&&output[(yPos&*&width)&+&xPos]&=&0xffff0000;&& &&&&&}&& &&& &&&&&//&draw&circle&at&x&y&& &&&&&private&void&drawCircle(int&pix,&int&xCenter,&int&yCenter)&{&& &&&&&&&&&pix&=&250;&//&颜色值,默认为白色&& &&& &&&&&&&&&int&x,&y,&r2;&& &&&&&&&&&int&rradius&=&r;&& &&&&&&&&&rr2&=&r&*&r;&& &&&&&&&&&&& &&&&&&&&&//&绘制圆的上下左右四个点&& &&&&&&&&&setPixel(pix,&xCenter,&yCenter&+&radius);&& &&&&&&&&&setPixel(pix,&xCenter,&yCenter&-&radius);&& &&&&&&&&&setPixel(pix,&xCenter&+&radius,&yCenter);&& &&&&&&&&&setPixel(pix,&xCenter&-&radius,&yCenter);&& &&& &&&&&&&&&y&=&radius;&& &&&&&&&&&x&=&1;&& &&&&&&&&&y&=&(int)&(Math.sqrt(r2&-&1)&+&0.5);&& &&&&&&&&&&& &&&&&&&&&//&边缘填充算法,&其实可以直接对循环所有像素,计算到做中心点距离来做&& &&&&&&&&&//&这个方法是别人写的,发现超赞,超好!&& &&&&&&&&&while&(x&&)&{&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&x,&yCenter&+&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&x,&yCenter&-&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&x,&yCenter&+&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&x,&yCenter&-&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&y,&yCenter&+&x);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&y,&yCenter&-&x);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&y,&yCenter&+&x);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&y,&yCenter&-&x);&& &&&&&&&&&&&&&x&+=&1;&& &&&&&&&&&&&&&y&=&(int)&(Math.sqrt(r2&-&x&*&x)&+&0.5);&& &&&&&&&&&}&& &&&&&&&&&if&(x&==&y)&{&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&x,&yCenter&+&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&+&x,&yCenter&-&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&x,&yCenter&+&y);&& &&&&&&&&&&&&&setPixel(pix,&xCenter&-&x,&yCenter&-&y);&& &&&&&&&&&}&& &&&&&}&& &&& &&&&&public&int[]&getAcc()&{&& &&&&&&&&&return&&& &&&&&}&& &&& &}&&&
测试的UI类:
package&com.gloomyfish.image.transform.&& &&& &import&java.awt.BorderL&& &import&java.awt.C&& &import&java.awt.D&& &import&java.awt.FlowL&& &import&java.awt.G&& &import&java.awt.Graphics2D;&& &import&java.awt.GridL&& &import&java.awt.event.ActionE&& &import&java.awt.event.ActionL&& &import&java.awt.image.BufferedI&& &import&java.io.F&& &&& &import&javax.imageio.ImageIO;&& &import&javax.swing.BorderF&& &import&javax.swing.JB&& &import&javax.swing.JF&& &import&javax.swing.JP&& &import&javax.swing.JS&& &import&javax.swing.event.ChangeE&& &import&javax.swing.event.ChangeL&& &&& &public&class&HoughUI&extends&JFrame&implements&ActionListener,&ChangeListener&{&& &&&&&/**& &&&&&&*&& &&&&&&*/&& &&&&&public&static&final&String&CMD_LINE&=&&Line&Detection&;&& &&&&&public&static&final&String&CMD_CIRCLE&=&&Circle&Detection&;&& &&&&&private&static&final&long&serialVersionUID&=&1L;&& &&&&&private&BufferedImage&sourceI&& &//&&private&BufferedImage&houghI&& &&&&&private&BufferedImage&resultI&& &&&&&private&JButton&lineB&& &&&&&private&JButton&circleB&& &&&&&private&JSlider&radiusS&& &&&&&private&JSlider&numberS&& &&&&&public&HoughUI(String&imagePath)&& &&&&&{&& &&&&&&&&&super(&GloomyFish-Image&Process&Demo&);&& &&&&&&&&&try{&& &&&&&&&&&&&&&File&file&=&new&File(imagePath);&& &&&&&&&&&&&&&sourceImage&=&ImageIO.read(file);&& &&&&&&&&&}&catch(Exception&e){&& &&&&&&&&&&&&&e.printStackTrace();&& &&&&&&&&&}&& &&&&&&&&&initComponent();&& &&&&&}&& &&&&&&& &&&&&private&void&initComponent()&{&& &&&&&&&&&int&RADIUS_MIN&=&1;&& &&&&&&&&&int&RADIUS_INIT&=&1;&& &&&&&&&&&int&RADIUS_MAX&=&51;&& &&&&&&&&&lineBtn&=&new&JButton(CMD_LINE);&& &&&&&&&&&circleBtn&=&new&JButton(CMD_CIRCLE);&& &&&&&&&&&radiusSlider&=&new&JSlider(JSlider.HORIZONTAL,&RADIUS_MIN,&RADIUS_MAX,&RADIUS_INIT);&& &&&&&&&&&radiusSlider.setMajorTickSpacing(10);&& &&&&&&&&&radiusSlider.setMinorTickSpacing(1);&& &&&&&&&&&radiusSlider.setPaintTicks(true);&& &&&&&&&&&radiusSlider.setPaintLabels(true);&& &&&&&&&&&numberSlider&=&new&JSlider(JSlider.HORIZONTAL,&RADIUS_MIN,&RADIUS_MAX,&RADIUS_INIT);&& &&&&&&&&&numberSlider.setMajorTickSpacing(10);&& &&&&&&&&&numberSlider.setMinorTickSpacing(1);&& &&&&&&&&&numberSlider.setPaintTicks(true);&& &&&&&&&&&numberSlider.setPaintLabels(true);&& &&&&&&&&&&& &&&&&&&&&JPanel&sliderPanel&=&new&JPanel();&& &&&&&&&&&sliderPanel.setLayout(new&GridLayout(1,&2));&& &&&&&&&&&sliderPanel.setBorder(BorderFactory.createTitledBorder(&Settings:&));&& &&&&&&&&&sliderPanel.add(radiusSlider);&& &&&&&&&&&sliderPanel.add(numberSlider);&& &&&&&&&&&JPanel&btnPanel&=&new&JPanel();&& &&&&&&&&&btnPanel.setLayout(new&FlowLayout(FlowLayout.RIGHT));&& &&&&&&&&&btnPanel.add(lineBtn);&& &&&&&&&&&btnPanel.add(circleBtn);&& &&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&JPanel&imagePanel&=&new&JPanel(){&& &&& &&&&&&&&&&&&&private&static&final&long&serialVersionUID&=&1L;&& &&& &&&&&&&&&&&&&protected&void&paintComponent(Graphics&g)&{&& &&&&&&&&&&&&&&&&&if(sourceImage&!=&null)&& &&&&&&&&&&&&&&&&&{&& &&&&&&&&&&&&&&&&&&&&&Graphics2D&g2&=&(Graphics2D)&g;&& &&&&&&&&&&&&&&&&&&&&&g2.drawImage(sourceImage,&10,&10,&sourceImage.getWidth(),&sourceImage.getHeight(),null);&& &&&&&&&&&&&&&&&&&&&&&g2.setPaint(Color.BLUE);&& &&&&&&&&&&&&&&&&&&&&&g2.drawString(&原图&,&10,&sourceImage.getHeight()&+&30);&& &&&&&&&&&&&&&&&&&&&&&if(resultImage&!=&null)&& &&&&&&&&&&&&&&&&&&&&&{&& &&&&&&&&&&&&&&&&&&&&&&&&&g2.drawImage(resultImage,&resultImage.getWidth()&+&20,&10,&resultImage.getWidth(),&resultImage.getHeight(),&null);&& &&&&&&&&&&&&&&&&&&&&&&&&&g2.drawString(&最终结果,红色是检测结果&,&resultImage.getWidth()&+&40,&sourceImage.getHeight()&+&30);&& &&&&&&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&&&&&}&& &&&&&&&&&&&&&}&& &&&&&&&&&&&&&&& &&&&&&&&&};&& &&&&&&&&&this.getContentPane().setLayout(new&BorderLayout());&& &&&&&&&&&this.getContentPane().add(sliderPanel,&BorderLayout.NORTH);&& &&&&&&&&&this.getContentPane().add(btnPanel,&BorderLayout.SOUTH);&& &&&&&&&&&this.getContentPane().add(imagePanel,&BorderLayout.CENTER);&& &&&&&&&&&&& &&&&&&&&&//&setup&listener&& &&&&&&&&&this.lineBtn.addActionListener(this);&& &&&&&&&&&this.circleBtn.addActionListener(this);&& &&&&&&&&&this.numberSlider.addChangeListener(this);&& &&&&&&&&&this.radiusSlider.addChangeListener(this);&& &&&&&}&& &&&&&&& &&&&&public&static&void&main(String[]&args)&& &&&&&{&& &&&&&&&&&String&filePath&=&System.getProperty&(&user.home&)&+&&/Desktop/&&+&&zhigang/hough-test.png&;&& &&&&&&&&&HoughUI&frame&=&new&HoughUI(filePath);&& &&&&&&&&&//&HoughUI&frame&=&new&HoughUI(&D:\\image-test\\lines.png&);&& &&&&&&&&&frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&& &&&&&&&&&frame.setPreferredSize(new&Dimension(800,&600));&& &&&&&&&&&frame.pack();&& &&&&&&&&&frame.setVisible(true);&& &&&&&}&& &&& &&&&&@Override&& &&&&&public&void&actionPerformed(ActionEvent&e)&{&& &&&&&&&&&if(e.getActionCommand().equals(CMD_LINE))&& &&&&&&&&&{&& &&&&&&&&&&&&&HoughFilter&filter&=&new&HoughFilter(HoughFilter.LINE_TYPE);&& &&&&&&&&&&&&&resultImage&=&filter.filter(sourceImage,&null);&& &&&&&&&&&&&&&this.repaint();&& &&&&&&&&&}&& &&&&&&&&&else&if(e.getActionCommand().equals(CMD_CIRCLE))&& &&&&&&&&&{&& &&&&&&&&&&&&&HoughFilter&filter&=&new&HoughFilter(HoughFilter.CIRCLE_TYPE);&& &&&&&&&&&&&&&resultImage&=&filter.filter(sourceImage,&null);&& &&&&&&&&&&&&&//&resultImage&=&filter.getHoughSpaceImage(sourceImage,&null);&& &&&&&&&&&&&&&this.repaint();&& &&&&&&&&&}&& &&&&&&&&&&& &&&&&}&& &&& &&&&&@Override&& &&&&&public&void&stateChanged(ChangeEvent&e)&{&& &&&&&&&&&//&TODO&Auto-generated&method&stub&& &&&&&&&&&&& &&&&&}&& &}&&&
五:霍夫变换检测圆与直线的图像预处理
使用霍夫变换检测圆与直线时候,一定要对图像进行预处理,灰度化以后,提取图像的边缘使用非最大信号压制得到一个像素宽的边缘, 这个步骤对霍夫变换非常重要.否则可能导致霍夫变换检测的严重失真.第一次用Mac发博文,编辑不好请见谅!
(责任编辑:6g下载网)
------分隔线----------------------------
本站所有软件和资料均为软件作者提供和网友推荐收集整理而来,仅供学习和研究使用。如有侵权,请联系站长QQ:
Copyright (C) g下载网().All Rights Reserved
黔ICP备号-2

我要回帖

更多关于 东风eq6420pf9报价 的文章

 

随机推荐