惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Troy Hunt's Blog
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
Cyberwarzone
Cyberwarzone
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
T
Threatpost
H
Heimdal Security Blog
W
WeLiveSecurity
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
IT之家
IT之家
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
TaoSecurity Blog
TaoSecurity Blog
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
量子位
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Vercel News
Vercel News
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security

博客园 - umlchina

.Net桌面程序自动更新NAppUpdate c# interview examination questions how to use wpf control in a winform application prism框架里module太多启动速度过慢 Localizing of WPF application Unity 中的拦截功能 Interception and Interceptors in C# (Aspect oriented programming) 转载 WPF Snippet Tutorial - Aligning ListView Items WPF Tutorial - How To Use A DataTemplateSelector Dependency Properties Introduction To Dependency Properties of WPF 朋友的公司招.net程序员2名及项目经理1名 Simple Object Access Protocol (SOAP) 1.1 how to create pdf by itextsharp 图片处理转换 how to design a hardware service use .net remoting : 使用SAAJ发送和接收SOAP消息 consume an asp.net webservice(upload a file to server) from java via soap 紧急求助:我们想做一个service程序,这个service负责统一管理这台机器上装的一些设备(包括签字板,扫描仪等等),
convert RGB colorspace to Homochromy(Black/whit) - umlchina
umlchina · 2008-03-27 · via 博客园 - umlchina

//convert RGB colorspace to Homochromy(Black/whit) 

  
static public int ConvertRGBtoHomochromy(int x,int bw)

  
{

        String rgbString 
= Integer.toHexString(x).toUpperCase();

        
if (rgbString.length()!=6)

        
{

              
return Integer.parseInt("000000"16);

        }


        String strR,strG,strB;

        strR 
= rgbString.substring(02);

        strG 
= rgbString.substring(24);

        strB 
= rgbString.substring(46);

        

        
int intR,intG,intB;

        intR 
= Integer.parseInt(strR, 16);

        intG 
= Integer.parseInt(strG, 16);

        intB 
= Integer.parseInt(strB, 16);

        
//get lum value from RGB

        
int y = (int)(0.299 * intR + 0.587 * intG + 0.114 * intB);

      
if(y>bw) 

      
{

        y 
= 255;

      }


      
else

      
{

        y 
= 0;

      }


        String result 
= Integer.toHexString(y).toUpperCase()+ Integer.toHexString(y).toUpperCase()

        
+ Integer.toHexString(y).toUpperCase();

        
return Integer.parseInt(result, 16);

  }


      ColorModel    cm    =image.getColorModel();

      if((image.getType()!=BufferedImage.TYPE_BYTE_BINARY)||(cm.getPixelSize()!=1)){

      //BufferedImage grayImage=new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_BYTE_BINARY);

      //grayImage.getGraphics().drawImage(image,0,0,null);

       WritableRaster   raster =image.getRaster();

         //image = grayImage;

         DataBufferInt   buffer=(DataBufferInt)raster.getDataBuffer();

         int[]           imgdata=(int[])buffer.getData();

         for(int i=0; i<imgdata.length;i++)

         {

             imgdata[i] = ConvertRGBtoHomochromy(imgdata[i],190);              

              //i=0;

         }

         image.setData(raster);

          //image = convert(image,BufferedImage.TYPE_BYTE_BINARY);

         File jpgFile = new File("C:""Documents and Settings""ar""My Documents","afterbw.jpg");jpgFile.delete();

         ImageIO.write(image, "jpg", jpgFile);

below code is how to get

threshold value from image for convertor.

static public int getThreshold(BufferedImage image)
  
{
      
int thresholdValue=1// threshold
      int[] ihist = new int[256]; //
      int i, j, k; // various counters
      int n, n1, n2, gmin, gmax;
      
double m1, m2, sum, csum, fmax, sb;
       
// reset
      for(i=0;i<256;i++){
        ihist[i] 
= 0;
      }

      gmin
=255; gmax=0;
      
for (i = 1; i < image.getWidth()-1 ; i++
      
{
          
for (j = 1; j < image.getHeight()-1 ; j++
          
{
               
//get gray value base on RGB value
              int cn = getGrayValue(image.getRGB(i, j));
               ihist[cn]
++;
              
if(cn > gmax) gmax=cn;
              
if(cn < gmin) gmin=cn;
              }

       }

       
// set up everything
       sum = csum = 0.0;
       n 
= 0;
       
for (k = 0; k <= 255; k++
       
{
           sum 
+= (double) k * (double) ihist[k]; /* x*f(x) */
           n 
+= ihist[k]; /* f(x) */
       }

       
if (n==0
       
{
        
// if n has no value, there is problems
        return (60);
       }

       
// do the otsu global thresholding method
       fmax = -1.0;
       n1 
= 0;
       
for (k = 0; k < 255; k++
       
{
           n1 
+= ihist[k];
           
if (n1==0continue; }
           n2 
= n - n1;
           
if (n2 == 0break; }
           csum 
+= (double) k *ihist[k];
           m1 
= csum / n1;
           m2 
= (sum - csum) / n2;
           sb 
= (double) n1 *(double) n2 *(m1 - m2) * (m1 - m2);
           
/* bbg: note: can be optimized. */
           
if (sb > fmax) 
           
{
               fmax 
= sb;
               thresholdValue 
= k;
           }

       }

       
// at this point we have our thresholding value
       return thresholdValue;      
  }

and the  orginal codes be changed:

  int thresholdValue = getThreshold(image);
         
for(int i=0; i<imgdata.length;i++)
         
{
             
//imgdata[i] = ConvertRGBtoGray(imgdata[i]);
             imgdata[i] = ConvertRGBtoHomochromy(imgdata[i],thresholdValue);             
             
//i=0;
         }

添加 edge detect ,用来找到边界去掉背景块

static public BufferedImage edgeDetect(BufferedImage img){

        
int w = img.getWidth(null);
        
int h = img.getHeight(null);
        BufferedImage newImage 
= new BufferedImage(w,h,1); 
        
for (int y=0;y<h;y++)

            
for (int x=0;x<w;x++){
                
int c=img.getRGB(x,y);
                newImage.setRGB(x,y,c);
            }

        
int c,red,green,blue,avg,d=3;
         
for (int y=0;y<h;y++)

             
for (int x=0;x<w;x++){

               c
=img.getRGB(x,y);
               red
=getRed(c);
               green
=getGreen(c);
               blue
=getBlue(c);
               avg
=(red+green+blue)/d;
               newImage.setRGB(x,y,createRGB(avg,avg,avg));
             }

         Kernel k 
= new Kernel(33new float[] 0.0f1.0f0.0f
                                                          
1.0f-4.0f1.0f
                                                          
0.0f1.0f0.0f }
);

               ConvolveOp op 
= new ConvolveOp(k);
               BufferedImage img2 
= op.filter(newImage, null);
               
return img2;     
    }



添加去杂点的处理方法:

static private int getMiddleValue(int[] arrayValue){
      
int v;
      
for(int i=0;i<=7;i++)
      
{
          
for(int j=0;j<=7;j++)
          
{
              
if (arrayValue[j]<arrayValue[j+1]) {
                 v 
= arrayValue[j];
                 arrayValue[j] 
= arrayValue[j+1];
                 arrayValue[j
+1= v;
              }
 
          }

      }

    
return arrayValue[5];
      
  }

  
  

static private BufferedImage Opt(BufferedImage image)
  
{   
      
int width = image.getWidth();
      
int height = image.getHeight();
      
      
int[] c = new int[9];
      
for(int i=1;i<width-1;i++)
      
{
          
for(int j=1;j<height-1;j++){
             
int cc = image.getRGB(i, j);
             c[
0= image.getRGB(i-1, j-1);
             c[
1= image.getRGB(i, j-1);
             c[
2= image.getRGB(i+1, j-1);
             c[
3= image.getRGB(i-1, j);
             c[
4= image.getRGB(i, j);
             c[
5= image.getRGB(i+1, j);
             c[
6= image.getRGB(i-1, j+1);
             c[
7= image.getRGB(i, j+1);
             c[
8= image.getRGB(i+1, j+1);
             cc 
= getMiddleValue(c);
             image.setRGB(i,j,cc);    
          }

      }

      
return image;
  }

更新edge detect 算法

static public int [] apply_sobel(int [] src_1d, int width, int height, double sobscale,
            
float offsetval) {

      
int i_w = width;
      
int i_h = height;
      
int d_w = width;
      
int d_h = height;
      
int[] dest_1d = new int[d_w * d_h];

      
for(int i=0;i<src_1d.length;i++){
          
try {

              
int a = src_1d[i] & 0x000000ff;
              
int b = src_1d[i+ 1& 0x000000ff;
              
int c = src_1d[i+ 2& 0x000000ff;
              
int d = src_1d[i + i_w] & 0x000000ff;
              
int e = src_1d[i + i_w + 2& 0x000000ff;
              
int f = src_1d[i + 2*i_w ] & 0x000000ff;
              
int g = src_1d[i + 2*i_w + 1& 0x000000ff;
              
int h = src_1d[i + 2*i_w + 2& 0x000000ff;
              
int hor = (a+d+f) - (c+e+h);
              
if (hor < 0) hor = -hor;
              
int vert = (a+b+c) - (f+g+h);
              
if (vert < 0) vert = -vert;
              
short gc = (short) (sobscale * (hor + vert));
              gc 
= (short) (gc + offsetval);
              
if (gc > 255) gc = 255;
              dest_1d[i] 
= 0xff000000 | gc<<16 | gc<<8 | gc;

  
//reached borders of image so goto next row
  
//(see Convolution.java)
              if (((i+3)%i_w)==0)  {
                  dest_1d[i] 
= 0;
                  dest_1d[i
+1= 0;
                  dest_1d[i
+2= 0;
                  i
+=3;
                  }

          }
 catch (ArrayIndexOutOfBoundsException e) {
//if reached row boudary of image return.
              i = src_1d.length;
          }

      }

      
return dest_1d;
  }