图像归一化java代码 图像归一化处理方法

JAVA实现归一化问题

最后一个数不用除法,改用减法,从总量中减去已知的数字

合江网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。

0.337

0.330

0.334

变成

0.337

0.330

0.333

谁有数字图像水印的 求出归一化互相关系数NC值的代码

%nc(归一化相关系数)函数源码

%计算nc(归一化相关系数)

function dNC = nc(ImageA,ImageB)

if (size(ImageA,1) ~= size(ImageB,1)) or (size(ImageA,2) ~= size(ImageB,2))

error('ImageA ImageB');

dNC = 0;

return ;

end

ImageA=double(ImageA);

ImageB=double(ImageB);

M = size(ImageA,1);

N = size(ImageA,2);

d1=0 ;

d2=0;

d3=0;

for i = 1:M

for j = 1:N

d1=d1+ImageA(i,j)*ImageB(i,j) ;

d2=d2+ImageA(i,j)*ImageA(i,j) ;

d3=d3+ImageB(i,j)*ImageB(i,j) ;

end

end

dNC=d1/(sqrt(d2)*sqrt(d3));

return

在函数调用时用

water=imread('D:\MATLAB7.1\work\water.bmp');

NC=nc(water,W)

%w为提取出来的水印

matlab图像处理为什么要归一化和如何归一化

1.

基本上归一化思想是利用图像的不变矩寻找一组参数使其能够消除其他变换函数对图

像变换的影响。也就是转换成唯一的标准形式以抵抗仿射变换

图像归一化使得图像可以抵抗几何变换的攻击,

它能够找出图像中的那些不变量,

从而

得知这些图像原本就是一样的或者一个系列的。

因为我们这次的图片有好多都是一个系列的,所以老师把这个也作为我研究的一个方

向。

我们主要要通过归一化减小医学图片由于光线不均匀造成的干扰。

2.matlab

里图像数据有时候必须是浮点型才能处理,而图像数据本身是

0-255

UNIT

型数

据所以需要归一化,转换到

0-1

之间。

3.

归一化是一种简化计算的方式,即将有量纲的表达式,经过变换,化为无量纲的表达式,

成为纯量。

目的是为了:

(1).

避免具有不同物理意义和量纲的输入变量不能平等使用

(2).bp

中常采用

sigmoid

函数作为转移函数,归一化能够防止净输入绝对值过大引起的神经

元输出饱和现象

(3).

保证输出数据中数值小的不被吞食

3.

神经网络中归一化的原因

归一化是为了加快训练网络的收敛性,可以不进行归一化处理

归一化的具体作用是归纳统一样本的统计分布性。

归一化在

0-1

之间是统计的概率

分布,归一化在

-1--+1

之间是统计的坐标分布。归一化有同一、统一和合一的意思。无论是

为了建模还是为了计算,

首先基本度量单位要同一,

神经网络是以样本在事件中的统计分别

几率来进行训练(概率计算)和预测的,归一化是同一在

0-1

之间的统计概率分布;

当所

有样本的输入信号都为正值时,

与第一隐含层神经元相连的权值只能同时增加或减小,

从而

导致学习速度很慢。

为了避免出现这种情况,

加快网络学习速度,

可以对输入信号进行归一

化,使得所有样本的输入信号其均值接近于

或与其均方差相比很小。

归一化是因为

sigmoid

函数的取值是

1

之间的,

网络最后一个节点的输出也是

如此,

所以经常要对样本的输出归一化处理。

所以这样做分类的问题时用

[0.9 0.1 0.1]

就要比

[1 0 0]

要好。

但是归一化处理并不总是合适的,

根据输出值的分布情况,

标准化等其它统计变换方法有时

可能更好。

二、如何归一化

matlab

中的归一化处理有三种方法

1. premnmx

postmnmx

tramnmx

2. restd

poststd

trastd

3.

自己编程

(1)

线性函数转换,表达式如下:

y=(x-MinValue)/(MaxValue-MinValue)

说明:

x

y

分别为转换前、后的值,

MaxValue

MinValue

说明:以

10

为底的对数函数转换。

(3)

反余切函数转换,表达式如下:

y=atan(x)*2/PI

(4)

一个归一化代码

.

I=double(I);

maxvalue=max(max(I)');%max

在把矩阵每列的最大值找到,

并组成一个单行的数组,

转置一

下就会行转换为列,再

max

就求一个最大的值,如果不转置,只能求出每列的最大值。

f = 1 - I/maxvalue; %

为什么要用

1

去减?

Image1=f;

图像归一化到

[0,255]

(im

-

min(min(im)))

./

(max(max(im))

min(min(im))) * 255

新手学习使用Java,尝试着做一个项目使用Java做一个视频图像的处理。

Java图像处理技巧四则

下面代码中用到的sourceImage是一个已经存在的Image对象

图像剪切

对于一个已经存在的Image对象,要得到它的一个局部图像,可以使用下面的步骤:

//import java.awt.*;

//import java.awt.image.*;

Image croppedImage;

ImageFilter cropFilter;

CropFilter =new CropImageFilter(25,30,75,75); //四个参数分别为图像起点坐标和宽高,即CropImageFilter(int x,int y,int width,int height),详细情况请参考API

CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));

如果是在Component的子类中使用,可以将上面的Toolkit.getDefaultToolkit().去掉。FilteredImageSource是一个ImageProducer对象。

图像缩放

对于一个已经存在的Image对象,得到它的一个缩放的Image对象可以使用Image的getScaledInstance方法:

Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT); //得到一个100X100的图像

Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT); //得到一个放大两倍的图像,这个程序一般在一个swing的组件中使用,而类Jcomponent实现了图像观察者接口ImageObserver,所有可以使用this。

//其它情况请参考API

灰度变换

下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+ B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。

/* GrayFilter.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class GrayFilter extends RGBImageFilter {

int modelStyle;

public GrayFilter() {

modelStyle=GrayModel.CS_MAX;

canFilterIndexColorModel=true;

}

public GrayFilter(int style) {

modelStyle=style;

canFilterIndexColorModel=true;

}

public void setColorModel(ColorModel cm) {

if (modelStyle==GrayModel

else if (modelStyle==GrayModel

}

public int filterRGB(int x,int y,int pixel) {

return pixel;

}

}

/* GrayModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class GrayModel extends ColorModel {

public static final int CS_MAX=0;

public static final int CS_FLOAT=1;

ColorModel sourceModel;

int modelStyle;

public GrayModel(ColorModel sourceModel) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

modelStyle=0;

}

public GrayModel(ColorModel sourceModel,int style) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

modelStyle=style;

}

public void setGrayStyle(int style) {

modelStyle=style;

}

protected int getGrayLevel(int pixel) {

if (modelStyle==CS_MAX) {

return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));

}

else if (modelStyle==CS_FLOAT){

return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);

}

else {

return 0;

}

}

public int getAlpha(int pixel) {

return sourceModel.getAlpha(pixel);

}

public int getRed(int pixel) {

return getGrayLevel(pixel);

}

public int getGreen(int pixel) {

return getGrayLevel(pixel);

}

public int getBlue(int pixel) {

return getGrayLevel(pixel);

}

public int getRGB(int pixel) {

int gray=getGrayLevel(pixel);

return (getAlpha(pixel)24)+(gray16)+(gray8)+gray;

}

}

如果你有自己的算法或者想取得特殊的效果,你可以修改类GrayModel的方法getGrayLevel()。

色彩变换

根据上面的原理,我们也可以实现色彩变换,这样的效果就很多了。下面是一个反转变换的例子:

/* ReverseColorModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class ReverseColorModel extends ColorModel {

ColorModel sourceModel;

public ReverseColorModel(ColorModel sourceModel) {

super(sourceModel.getPixelSize());

this.sourceModel=sourceModel;

}

public int getAlpha(int pixel) {

return sourceModel.getAlpha(pixel);

}

public int getRed(int pixel) {

return ~sourceModel.getRed(pixel);

}

public int getGreen(int pixel) {

return ~sourceModel.getGreen(pixel);

}

public int getBlue(int pixel) {

return ~sourceModel.getBlue(pixel);

}

public int getRGB(int pixel) {

return (getAlpha(pixel)24)+(getRed(pixel)16)+(getGreen(pixel)8)+getBlue(pixel);

}

}

/* ReverseColorModel.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.image.*;

public class ReverseFilter extends RGBImageFilter {

public ReverseFilter() {

canFilterIndexColorModel=true;

}

public void setColorModel(ColorModel cm) {

substituteColorModel(cm,new ReverseColorModel(cm));

}

public int filterRGB(int x,int y,int pixel) {

return pixel;

}

}

要想取得自己的效果,需要修改ReverseColorModel.java中的三个方法,getRed、getGreen、getBlue。

下面是上面的效果的一个总的演示程序。

/*GrayImage.java*/

/*@author:cherami */

/*email:cherami@163.net*/

import java.awt.*;

import java.awt.image.*;

import javax.swing.*;

import java.awt.color.*;

public class GrayImage extends JFrame{

Image source,gray,gray3,clip,bigimg;

BufferedImage bimg,gray2;

GrayFilter filter,filter2;

ImageIcon ii;

ImageFilter cropFilter;

int iw,ih;

public GrayImage() {

ii=new ImageIcon(\"images/11.gif\");

source=ii.getImage();

iw=source.getWidth(this);

ih=source.getHeight(this);

filter=new GrayFilter();

filter2=new GrayFilter(GrayModel.CS_FLOAT);

gray=createImage(new FilteredImageSource(source.getSource(),filter));

gray3=createImage(new FilteredImageSource(source.getSource(),filter2));

cropFilter=new CropImageFilter(5,5,iw-5,ih-5);

clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));

bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);

MediaTracker mt=new MediaTracker(this);

mt.addImage(gray,0);

try {

mt.waitForAll();

} catch (Exception e) {

}


网页名称:图像归一化java代码 图像归一化处理方法
浏览路径:http://ybzwz.com/article/dogjecs.html