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 图像扫描器---基于扫描线的更多相关文章

  1. Atitit 图像金字塔原理与概率 attilax的理解总结qb23

    Atitit 图像金字塔原理与概率 attilax的理解总结qb23 1.1. 高斯金字塔  (  Gaussianpyramid): 拉普拉斯金字塔 (Laplacianpyramid):1 1.2 ...

  2. Atitit 图像清晰度 模糊度 检测 识别 评价算法 源码实现attilax总结

    Atitit 图像清晰度 模糊度 检测 识别 评价算法 源码实现attilax总结 1.1. 原理,主要使用像素模糊后的差别会变小1 1.2. 具体流程1 1.3. 提升性能 可以使用采样法即可..1 ...

  3. Atitit 图像清晰度 模糊度 检测 识别 评价算法 原理

    Atitit 图像清晰度 模糊度 检测 识别 评价算法 原理 1.1. 图像边缘一般都是通过对图像进行梯度运算来实现的1 1.2. Remark: 1 1.3.  1.失焦检测. 衡量画面模糊的主要方 ...

  4. Atitit.prototype-base class-based  基于“类” vs 基于“原型”

    Atitit.prototype-base class-based  基于“类” vs 基于“原型” 1. 基于“类” vs 基于“原型”1 2.  对象的产生有两种基本方式.一种是以原型(proto ...

  5. 图像切割—基于图的图像切割(Graph-Based Image Segmentation)

     图像切割-基于图的图像切割(Graph-Based Image Segmentation) Reference: Efficient Graph-Based Image Segmentation ...

  6. 基于稀疏表示的图像超分辨率《Image Super-Resolution Via Sparse Representation》

    由于最近正在做图像超分辨重建方面的研究,有幸看到了杨建超老师和马毅老师等大牛于2010年发表的一篇关于图像超分辨率的经典论文<ImageSuper-Resolution Via Sparse R ...

  7. 基于传统方法点云分割以及PCL中分割模块

      之前在微信公众号中更新了以下几个章节 1,如何学习PCL以及一些基础的知识 2,PCL中IO口以及common模块的介绍 3,PCL中常用的两种数据结构KDtree以及Octree树的介绍    ...

  8. Atitit s2018 s3 doc list alldvc.docx .docx s2018 s3f doc compc s2018 s3f doc homepc sum doc dvcCompc dtS312 s2018 s3f doc compc\Atitit PathUtil 工具新特性新版本 v8 s312.docx s2018 s3f doc compc\Atitit 操作日

    Atitit s2018 s3 doc list alldvc.docx .docx s2018 s3f doc compc s2018 s3f doc homepc sum doc dvcCompc ...

  9. Atitit s2018.2 s2 doc list on home ntpc.docx  \Atiitt uke制度体系 法律 法规 规章 条例 国王诏书.docx \Atiitt 手写文字识别 讯飞科大 语音云.docx \Atitit 代码托管与虚拟主机.docx \Atitit 企业文化 每日心灵 鸡汤 值班 发布.docx \Atitit 几大研发体系对比 Stage-Gat

    Atitit s2018.2 s2 doc list on home ntpc.docx \Atiitt uke制度体系  法律 法规 规章 条例 国王诏书.docx \Atiitt 手写文字识别   ...

随机推荐

  1. C#引用类型(class)和值类型(struct)

    1. 值参数 当利用值向方法传递参数时,编译程序给实参的值做一份拷贝,并且将此拷贝传递给该方法.被调用的方法不传内存中实参的值,所以使用值参数时,可以保证实际值是安全的. using System; ...

  2. Linux三剑客之awk

    awk awk是linux下的一个命令,他对其他命令的输出,对文件的处理都十分强大,其实他更像一门编程语言,他可以自定义变量,有条件语句,有循环,有数组,有正则,有函数等.他读取输出,或者文件的方式是 ...

  3. PHP对象转数组||PHP数组转对象

    function arrayToObject($e){     if( gettype($e)!='array' ) return;     foreach($e as $k=>$v){     ...

  4. linux下rm -r误删NTFS文件恢复方法

    一时疏忽,手一抖,把整个挂载的F盘删了一半!顿时傻眼!! 被删的F盘是Windows下NTFS分区,在Ubuntu12.04中挂载了F盘,使用rm命令时粗心大意,误删了一半的数据. 血的教训告诉我们, ...

  5. Eclipse JAVA项目的 目录结构 和 导入

    说明:本文所有测试以java工程为例: 1. Eclipse下的java工程目录 eclipse的基本工程目录叫做workspace,每个运行时的eclipse实例只能对应一个workspace,也就 ...

  6. <Oracle Database>逻辑结构

    逻辑结构 Oracle的逻辑结构是一种层次结构.主要由:表空间.段.区和数据块等概念组成.逻辑结构是面向用户的,用户使用Oracle开发应用程序使用的就是逻辑结构. 数据块 数据块是Oracle最小的 ...

  7. [UE4]自定义MovementComponent组件

    自定义Movement组件 目的:实现自定义轨迹如抛物线,线性,定点等运动方式,作为组件控制绑定对象的运动. 基类:UMovementComponent 过程: 1.创建UCustomMovement ...

  8. Python学习之路--select解析

    sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后, ...

  9. linux sort,uniq,cut,wc命令详解

    linux sort,uniq,cut,wc命令详解 sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些 ...

  10. MySQL JDBC 出现多个 SHOW VARIABLES 语句。

    一次偶然的机会,show processlist 的时候,发现有个 Client 一直在执行  "mysql-connector-java-5.1.21 ( Revision: ${bzr. ...