Atitit 图像扫描器---基于扫描线
Atitit 图像扫描器---基于扫描线
调用范例
* @throws FileExistEx
*/
public static void main(String[] args) throws FileExistEx {
String s = "C:\\00p\\a1115_210836_162 dilate.jpg.png";
String ext = filex.getExtName(s);
// s="C:\\00capch\\p5.jpg";
BufferedImage src = imgx.toImg(s);
ImgTraver_lineScaner trvr = new ImgTraver_lineScaner().setSrc(src);
trvr.cur_Pix_Point_process_Fun_Handler = pnt -> {
int rgb = src.getRGB(pnt.x, pnt.y);
HSV hsv = ColorUtil.rgb2hsv(rgb);
// System.out.println(pnt+ "hsv:"+hsv);
if (hsv.v < 0.6) // dark clolor
throw new CurPixArrivdBoderEx();
};
Rectangle rect = trvr.trav();
package com.attilax.img;
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.function.Function;
import com.attilax.img.other.CurPixArrivdBoderEx;
import com.attilax.img.other.LineArrivdBorderEx;
import com.attilax.img.other.NewLineColorCheck;
import com.attilax.img.other.ProcessPointColor;
import com.attilax.io.FileExistEx;
import com.attilax.io.filex;
public class ImgTraver_lineScaner {
public static void main(String[] args) {
String s = "C:\\00p\\a1115_210836_162 dilate.jpg";
// s="C:\\00capch\\p5.jpg";
BufferedImage src = imgx.toImg(s);
// Rectangle rect=new ImgTraver_lineScaner().setSrc(src)
//new Rectangle(x, y, width, height)
// t();
System.out.println("--f");
}
private static void t() {
BufferedImage dest = null ;//= new DilateFilterV3().filter(src, null);
// BufferedImage dest= imgx.clone(src);
try {
imgx.save_png(dest, "C:\\00p\\a" + filex.getUUidName() + " dilate.jpg",false);
} catch (FileExistEx e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public BufferedImage getSrc() {
return src;
}
public ImgTraver_lineScaner setSrc(BufferedImage src) {
this.src = src;return this;
}
public void trave_downScan_lineByline(BufferedImage src, Point ini_select_Point_just4x) throws LineArrivdBorderEx {
int width = src.getWidth();
int height = src.getHeight();
for (int y = ini_select_Point_just4x.y; y < height; y++) {
scanLine(src, ini_select_Point_just4x, y);
}
}
public void trave_toDownScan_lineByline(BufferedImage src, Point ini_select_Point_just4x) throws LineArrivdBorderEx, CurPixArrivdBoderEx {
int width = src.getWidth();
int height = src.getHeight();
for (int y = ini_select_Point_just4x.y; y < height; y++) {
scanLineV2(src, ini_select_Point_just4x, y);
}
}
public ProcessPointColor cur_Pix_Point_process_Fun_Handler;
public Function<Integer,Boolean> checkIsMeetBorderPix_Handler;
public Function new_line_upNdown_evt_handler;
public Function new_line_scanFinish_evt_handler;
private BufferedImage src;
//public NewLineColorCheck newLineFirstColorCheckFun;
private void scanLine(BufferedImage src, Point ini_selectedPoint, int y) throws LineArrivdBorderEx {
new_line_upNdown_evt_handler.apply(new Point(ini_selectedPoint.x,y));
int cur_line_point_color = src.getRGB(ini_selectedPoint.x, y);// x is ini,y is next line point
if (checkIsMeetBorderPix_Handler.apply(cur_line_point_color))
throw new LineArrivdBorderEx();
// left scan
try {
leftScan(src, ini_selectedPoint, y);
} catch (CurPixArrivdBoderEx e) {
}
// right scan
try {
rightScan(src, ini_selectedPoint, y);
} catch (CurPixArrivdBoderEx e) {
}
}
private void scanLineV2(BufferedImage src, Point ini_selectedPoint, int y) throws LineArrivdBorderEx, CurPixArrivdBoderEx {
if(new_line_upNdown_evt_handler!=null)
new_line_upNdown_evt_handler.apply(new Point(ini_selectedPoint.x,y));
int cur_line_point_color = src.getRGB(ini_selectedPoint.x, y);// x is ini,y is next line point
if(checkIsMeetBorderPix_Handler!=null)
if (checkIsMeetBorderPix_Handler.apply(cur_line_point_color))
throw new LineArrivdBorderEx();
// left scan
leftScan(src, ini_selectedPoint, y);
// right scan
rightScan(src, ini_selectedPoint, y);
}
public void trave_upScan_lineByLine(BufferedImage src, Point ini_selectedPoint) throws LineArrivdBorderEx {
int width = src.getWidth();
int height = src.getHeight();
// ini_select_color_int = src.getRGB(ini_selectedPoint.x, ini_selectedPoint.y);
for (int y = ini_selectedPoint.y-1; y >0; y--) {
scanLine(src, ini_selectedPoint, y);
}
}
public void trave_toUpScan_lineByLine(BufferedImage src, Point ini_selectedPoint) throws LineArrivdBorderEx, CurPixArrivdBoderEx {
int width = src.getWidth();
int height = src.getHeight();
// ini_select_color_int = src.getRGB(ini_selectedPoint.x, ini_selectedPoint.y);
for (int y = ini_selectedPoint.y-1; y >0; y--) {
scanLineV2(src, ini_selectedPoint, y);
}
}
public void trave_toRitScan_lineByLine(int startX) throws LineArrivdBorderEx, CurPixArrivdBoderEx {
int width = src.getWidth();
int height = src.getHeight();
// ini_select_color_int = src.getRGB(ini_selectedPoint.x, ini_selectedPoint.y);
for (int x = startX; x<src.getWidth(); x++) {
scanLine_vert(x);
//scanLine(src, ini_selectedPoint, y);
if(new_line_scanFinish_evt_handler!=null)
new_line_scanFinish_evt_handler.apply(null);
}
}
/**
attilax 2016年11月16日 下午3:13:00
* @param src
* @param x
* @throws CurPixArrivdBoderEx
*/
@Deprecated
private void scanLine_vert_toRit(BufferedImage src, int x) throws CurPixArrivdBoderEx {
for (int y = 0; y<src.getHeight(); y++) {
if(x==15)
System.out.println("dbg");
Point preLeftPoint=new Point(x, y);
if(x<9)
{
System.out.println("dbg");
}
int clr=src.getRGB(preLeftPoint.x,preLeftPoint. y);
//if(checkIsMeetBorderPix_Handler.apply(clr))
this.cur_Pix_Point_process_Fun_Handler.apply(preLeftPoint);
//
}
}
public Point nowPoint;
public void trave_toLeftScan_lineByLine(int startX) throws LineArrivdBorderEx {
int width = src.getWidth();
int height = src.getHeight();
// ini_select_color_int = src.getRGB(ini_selectedPoint.x, ini_selectedPoint.y);
for (int x=startX;x>0;x--) {
try {
scanLine_vert( x);
} catch (CurPixArrivdBoderEx e) {
throw new LineArrivdBorderEx();
}
}
}
/**
attilax 2016年11月16日 下午3:23:11
* @param x
* @throws CurPixArrivdBoderEx
*/
private void scanLine_vert(int x) throws CurPixArrivdBoderEx {
for (int y = 0; y<src.getHeight(); y++) {
nowPoint=new Point(x, y);
if(x==15)
System.out.println("dbg");
Point preLeftPoint=new Point(x, y);
if(x<9)
{
System.out.println("dbg");
}
int clr=src.getRGB(preLeftPoint.x,preLeftPoint. y);
//if(checkIsMeetBorderPix_Handler.apply(clr))
this.cur_Pix_Point_process_Fun_Handler.apply(preLeftPoint);
//
}
}
/**
* left and curSelectPoint
* @param src
* @param ini_selectedPoint
* @param y
* @throws CurPixArrivdBoderEx
*/
private void leftScan(BufferedImage src,Point ini_selectedPoint, int y) throws CurPixArrivdBoderEx {
for (int x = ini_selectedPoint.x; x > 0; x--) {
if(x==15)
System.out.println("dbg");
Point preLeftPoint=new Point(x, y);
if(x<9)
{
System.out.println("dbg");
}
int clr=src.getRGB(preLeftPoint.x,preLeftPoint. y);
//if(checkIsMeetBorderPix_Handler.apply(clr))
this.cur_Pix_Point_process_Fun_Handler.apply(preLeftPoint);
//
}
}
private void rightScan(BufferedImage src, Point selectedPoint, int y) throws CurPixArrivdBoderEx {
//int select_color_int = src.getRGB(selectedPoint.x, selectedPoint.y);//-65536 red
//Color curClr=new Color(ini_select_color_int);
for (int x = selectedPoint.x+1; x < src.getWidth(); x++) {
Point nextRightPoint=new Point(x, y);
nowPoint=nextRightPoint;
this.cur_Pix_Point_process_Fun_Handler.apply(nextRightPoint);
}
}
/**
attilax 2016年11月9日 下午6:47:18
* @param img
* @param startPixPoint
*/
public void scan_Byline_from_startPixPoint(BufferedImage img, Point startPixPoint) {
try {
trave_downScan_lineByline(img, startPixPoint);
} catch (LineArrivdBorderEx e) {
}
try {
trave_upScan_lineByLine(img, startPixPoint);
} catch (LineArrivdBorderEx e) {
}
}
/**
attilax 2016年11月16日 下午3:37:24
* @return
*/
public Rectangle trav() {
int lastX = 0; int x = 0;int y = 0;int lastY = 0;
try {
trave_toLeftScan_lineByLine(src.getWidth()-1);
} catch (LineArrivdBorderEx e ) {
System.out.println(e.getMessage());
lastX=nowPoint.x;
if(lastX+2 <src.getWidth())
lastX=lastX+2;
}
try {
trave_toRitScan_lineByLine(0);
} catch (LineArrivdBorderEx | CurPixArrivdBoderEx e) {
System.out.println(e.getMessage());
x=nowPoint.x;
if(x-1!=0)
x=x-1;
}
try {
trave_toDownScan_lineByline(src,new Point(0,0) );
} catch (LineArrivdBorderEx | CurPixArrivdBoderEx e) {
System.out.println(e.getMessage());
y=nowPoint.y;
if(y-1!=0)
y=y-1;
}
try {
trave_toUpScan_lineByLine(src, new Point(0,src.getHeight()-1 ));
} catch (LineArrivdBorderEx | CurPixArrivdBoderEx e) {
System.out.println(e.getMessage());
lastY=nowPoint.y;
if(lastY+2 <src.getHeight())
lastY=lastY+2;
}
return new Rectangle(x, y, lastX-x, lastY-y);
}
}
作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 )
汉字名:艾提拉(艾龙), EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
Atiend
Atitit 图像扫描器---基于扫描线相关推荐
- 9.4 Python图像处理之图像数学形态学-基于灰度形态学的应用(形态梯度、形态平滑、高帽变换、低帽变换)
9.4 Python图像处理之图像数学形态学-基于灰度形态学的应用(形态梯度.形态平滑.高帽变换.低帽变换) 文章目录 9.4 Python图像处理之图像数学形态学-基于灰度形态学的应用(形态梯度.形 ...
- 二维海浪波数谱的matlab,一种海杂波图像下基于最小区间思想的海浪主波周期反演方法...
一种海杂波图像下基于最小区间思想的海浪主波周期反演方法 [专利摘要]本发明属于海杂波图像下海浪参数分析[技术领域],具体涉及一种海杂波图像下基于最小区间思想的海浪主波周期反演方法.本发明包括:基于雷达 ...
- 用幂次变换来增强图像matlab,基于幂次变换及MSR光照不均图像增强.doc
基于幂次变换及MSR光照不均图像增强 基于幂次变换及MSR光照不均图像增强摘要:针对光照不均图像暗区细节丢失的问题,提出了基于幂次变换和MSR(多尺度Retinex)的光照不均图像增强算法.首先对光照 ...
- open cv平面对象检测及翘曲图像校正-基于FLANN的特征检测和透视变换
接着上篇FLANN特征匹配,从上篇可以知道,如果特征匹配时全部是用线进行匹配,匹配效果并不能达到一目了然的效果 那么,可不可以把匹配到的结果用矩形或圆表示出来呢 当然可以,这就是平面对象识别 关于基于 ...
- 用matlab写的视频截取图像桢,基于MATLAB的储粮害虫图像处理方法
摘要:在对粮虫图像处理过程中,介绍了Matlab图像处理工具箱中的函数,给出了图像处理 与分析的技术实现, 边缘检测及轮廓提取, 通过形态学方法进行图像特征抽取与分析,达到了比较好的效果. 关键词:粮 ...
- c语言 投影法图像定位,基于抛物线拟合和边缘点搜索的虹膜精确定位
摘 要: 虹膜的定位包括瞳孔(内圆)和虹膜外圆的定位.该方法首先预判断瞳孔中心和半径截取目标区域小图,然后对目标区域提取边缘采用最小二乘抛物线拟合,算出左右固定区域内边缘点极值点坐标,得到瞳孔初始的 ...
- matlab画波动图像,【基于Matlab的波动方程的可视化实现最终版材料】
基于Matlab的波动方程的可视化实现(最终版) <基于Matlab的波动方程的可视化实现.doc>由会员分享,可免费在线阅读全文,更多与<基于Matlab的波动方程的可视化实现(最 ...
- c语言图像压缩编码,基于C语言的图像压缩算法
摘要:该文借鉴静态图像压缩标准JPEG的理论研究成果,将其与DCT快速变换相结合,采用霍夫曼编码方法,用C语言编程实现灰度图像的压缩.最后,计算了基于DCT快速变换的图像压缩算法的压缩比.同时,分析了 ...
- html设计一组图像画廊,基于CSS3的图片画廊的设计与实现
陈纪霞 摘要:CSS3的出现给WEB开发带来了革命性的影响,以前很多需要javascript实现的复杂效果,现在使用简单的CSS3就能实现.该文就利用CSS3实现了一个绚丽的图片画廊效果. 关键词:C ...
最新文章
- [ActiveMQ]初识ActiveMQ
- 快速排序 动图_Java十大排序算法最强总结
- 【英语学习】【WOTD】finicky 释义/词源/示例
- mysql默认存储引擎的索引结构是_InnoDB引擎的索引和存储结构
- 速度逆天的Android模拟器——Genymotion
- 转:关于数据库压缩技术的Survey
- MySQL批处理SQL语句
- 年薪百万是社会认同,更是自身价值体现
- 【光学】基于matlab涡旋光与球面波的干涉【含Matlab源码 597期】
- Unity3D NGUI图文混排聊天表情
- PDF怎么编辑修改,如何编辑PDF文字内容
- 一文看雷击浪涌的防护解析
- win10 linux双系统卸载,win10双系统卸载ubuntu的方法
- Mount is denied because the NTFS volume is already exclusively opened.
- 用python的turtle库画个笑脸(附代码)
- ecshop模板制作5-调整首页样式
- MYSQL中redo log和binlog之间的区别
- 计算机成瘾的危险英语对话,英语作文:论孩子们对电脑游戏上瘾
- 国产品牌积极布局,游戏手机会是行业增长新风口吗?
- 【Java】奇偶数判断
热门文章
- Input为number类型maxlength不好使,用js轻松解决
- Tkinter的Menu组件
- 从冲咖啡看统计过程控制
- 归纳:数据库设计的六个阶段详解(有这一篇就够了)
- mysql中int最大多少,int(11)最大長度是多少,MySQL中varchar最大長度是多少(轉)
- shadowplay要下载java_Java并发程序设计(二)Java并行程序基础
- PPT 下载 | 神策数据徐美玲:如何挖好数据这座矿?
- 神策数据斩获三殊荣,美通社小饭桌正和岛齐认可
- [CF487E]Tourists
- 算法转AI平台工程师记录-0