一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值

一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值,第1张

%我觉得是你计算 PSNR的方法错了,应该是用最大像素值,

%灰度图像的最大像素值是255, 而不是512。

%另外计算MSE也不用那么麻烦

%下面是计算 MSE和PSNR的程序,我拿一张试了一下,结果肯定是不一样的。

%还有统计像素值出现的次数,用直方图imhist会更简单点,这个程序我没写。

I=imread('boatbmp');

J=imnoise(I,'gaussian',0,001);

Jg=double(J);

%均值滤波

k1=filter2(fspecial('average',3),Jg);

k2=filter2(fspecial('average',5),Jg);

figure,subplot(221),imshow(I);title('原图');

subplot(222),imshow(J);title('加入高斯白噪声以后的图像');

subplot(223),imshow(uint8(k1));title('33模板均值滤波');

subplot(224),imshow(uint8(k2));title('55模板均值滤波');

%中值滤波

k3=medfilt2(Jg,[3 3]);

k4=medfilt2(Jg,[5 5]);

figure,subplot(221),imshow(I);title('原图');

subplot(222),imshow(J);title('加入高斯白噪声以后的图像');

subplot(223),imshow(uint8(k3));title('33模板中值滤波');

subplot(224),imshow(uint8(k4));title('55模板中值滤波');

%计算均值滤波后图像的PMSE与PSNR

diff=(double(I)-k1)^2;

mse=mean(diff(:));

pmse_avg=mse;

max_value=max(k1(:));

psnr=double(10log(max_valuemax_value/mse)/log(10));

%计算中值滤波后的各项指标

diff=(double(I)-k3)^2;

mse=mean(diff(:));

max_value=max(k3(:));

pmse_mid=mse;

psnr_mid=double(10log(max_valuemax_value/mse)/log(10));

可以参考下面的程序,其中bitCount!=8 && bitCount!=24指的就是8位与24位

//BMP与IplImage相互转换

///////////////////////////////头文件bmp2iplh

//bmp2iplh

#ifndef BMP2IPL_H

#define BMP2IPL_H

class BMP {

public:

BMP():bmpData(NULL) {

memset(&biHeader, 0, sizeof(biHeader));

}

BMP(const BMP & img);

BMP(const IplImage &img);

BMP(int width, int height, int bitCount);

~BMP(){ delete [] bmpData; }

bool CreateImage(const BITMAPINFOHEADER &biHeader);

//Export

IplImage BMP2Ipl();

//void Show(HWND hWnd, int nID);

//void Show(CDC pDC, CRect & rect);

//void Show(HWND hWnd);

void ReSize(int newW, int newH);

private:

void CopyData(char dest, const char src, int dataByteSize,

bool isConvert, int height);

// isConvert=true 进行顶左和底左之间的转换(顶左到底左或底左到顶左),否则不转换

// biSizeImage may be set to zero for BI_RGB bitmaps, so calculate it

int ImgSize() {

return ( biHeaderbiHeight ((biHeaderbiWidth biHeaderbiBitCount / 8 + 3) & (-4)));

}

public:

void Clear();

BITMAPINFOHEADER biHeader;

unsigned char bmpData;

};

#endif

/////////////////////////////////////////////////////////////////////实现文件bmp2iplcpp

#include "bmp2iplh"

/

NOTE:

Only use the "8 bit, 1 or 3 channels" image, the BitMap use LowerLeft (底左),

the IplImage use TopLeft (顶左)

IplImage:

nChannels = 1 or 3 number of channels

depth = IPL_DEPTH_8U pixel depth (8 bit), IPL_DEPTH_8U=8

dataOrder = 0 交叉存取颜色通道

origin = IPL_ORIGIN_TL 图像数据保存形式,IPL_ORIGIN_BL底左结构, IPL_ORIGIN_TL顶左结构

align = 4 行数据对齐方式,保证下一行数据从整4字节位置开始

width

height

widthStep 图像数据行大小,单位字节

imageSize 图像数据大小(=heightwidthStep),单位字节

imageData 指向图像数据区,char

BITMAPINFOHEADER:

biSize Specifies the number of bytes required by the structure

biWidth

biHeight(>0) biHeight>0底左结构;biHeight<0顶左结构

biPlanes = 1 Specifies the number of planes for the target device This value

must be set to 1

biBitCount =8 or 24 bits-per-pixel,8-(pixelDepth=8,channels=1),

24-(pixelDepth=8,channels=3)

biCompression = BI_RGB An uncompressed format

biSizeImage Specifies the size, in bytes, of the imageThis may be set to zero

for BI_RGB bitmaps

biXPelsPerMeter = 0

biYPelsPerMeter = 0

biClrUsed = 0

biClrImportant = 0

/

BMP::BMP(const BMP & img)

{

if(!IsSupport(img)) {

BMP();

return;

}

//biHeader = imgbiHeader;

PBITMAPINFOHEADER pBmpH = (PBITMAPINFOHEADER)&imgbiHeader;

memcpy(&biHeader, pBmpH, sizeof(BITMAPINFOHEADER));

biHeaderbiSizeImage = ImgSize();

bool isLowerLeft = biHeaderbiHeight>0;

//int rowSize=0;

if(!isLowerLeft) biHeaderbiHeight=-biHeaderbiHeight;

if(bmpData!=NULL) delete[] bmpData;

bmpData = new unsigned char [biHeaderbiSizeImage];

//memcpy(bmpData, imgbmpData, imgbiHeaderbiSizeImage);

CopyData((char )bmpData, (char)imgbmpData, biHeaderbiSizeImage,

!isLowerLeft, biHeaderbiHeight);

}

BMP::BMP(const IplImage &img) {

if(!IsSupport(img)) {

BMP();

return;

}

bool isTopLeft = (imgorigin == IPL_ORIGIN_TL);

biHeaderbiSize = sizeof(BITMAPINFOHEADER);

biHeaderbiWidth = imgwidth;

biHeaderbiHeight = imgheight;

biHeaderbiPlanes = 1;

biHeaderbiBitCount = imgdepth imgnChannels;

biHeaderbiCompression = BI_RGB;

biHeaderbiSizeImage = imgimageSize;

biHeaderbiXPelsPerMeter = 0;

biHeaderbiYPelsPerMeter = 0;

biHeaderbiClrUsed = 0;

biHeaderbiClrImportant = 0;

if(bmpData!=NULL) delete[] bmpData;

bmpData = new unsigned char [imgimageSize];

//memcpy(bmpData, imgImageData, imgimageSize);

CopyData((char)bmpData, (char)imgimageData, imgimageSize,

isTopLeft, imgheight);

/int i,j;

CvScalar s;

for(i=0;i<imgwidth;i++)

for(j=0;j<imgheight;j++){

s=cvGet2D(&img,i,j);

}

/

}

BMP::BMP(int width, int height, int bitCount) {

if(bitCount!=8 && bitCount!=24) return;

biHeaderbiSize = sizeof(BITMAPINFOHEADER);

biHeaderbiWidth = width;

biHeaderbiHeight = height;

biHeaderbiPlanes = 1;

biHeaderbiBitCount = bitCount;

biHeaderbiCompression = BI_RGB;

biHeaderbiSizeImage = ImgSize();

biHeaderbiXPelsPerMeter = 0;

biHeaderbiYPelsPerMeter = 0;

biHeaderbiClrUsed = 0;

biHeaderbiClrImportant = 0;

if(bmpData!=NULL) delete[] bmpData;

bmpData = new unsigned char [biHeaderbiSizeImage];

Clear();

}

// dest: the destination image

// dataByteSize: the Source image

// height: source image height

void BMP::CopyData(char dest, const char src, int dataByteSize,

bool isConvert, int height) {

char p = dest;

if(!isConvert) {

memcpy(dest, src, dataByteSize);

return;

}

if(height<=0) return;

//int height = dataByteSize/rowByteSize;

int rowByteSize = dataByteSize / height;

src = src + dataByteSize - rowByteSize ;

for(int i=0; i<height; i++) {

memcpy(dest, src, rowByteSize);

dest += rowByteSize;

src -= rowByteSize;

}

}

IplImage BMP::BMP2Ipl() {

if(!IsSupport(this)) return NULL;

IplImage iplImg;

int height;

bool isLowerLeft = biHeaderbiHeight>0;

height = (biHeaderbiHeight>0) biHeaderbiHeight : -biHeaderbiHeight;

iplImg = cvCreateImage( cvSize(biHeaderbiWidth, height), IPL_DEPTH_8U, biHeaderbiBitCount / 8);

//iplImg = cvCreateImageHeader( cvSize(biHeaderbiWidth, height), IPL_DEPTH_8U, biHeaderbiBitCount / 8);

//cvSetData(iplImg,(char)bmpData,biHeaderbiSizeImage/height);

CopyData( iplImg->imageData, (char)bmpData, biHeaderbiSizeImage,

isLowerLeft, height);

/int i,j;

CvScalar s;

int channels=biHeaderbiBitCount / 8;

int step=(biHeaderbiWidthchannels+3) & -4;

int loc=0;

for(i=0;i<iplImg->height;i++){

for(j=0;j<iplImg->width;j++){

loc=istep + jchannels;

sval[0]=bmpData[loc];

if(channels==3){

sval[1]=bmpData[loc+1];

sval[2]=bmpData[loc+2];

}

cvSet2D(iplImg,i,j,s);

}

}/

return iplImg;

}

void BMP::Clear() {

if(bmpData == NULL) return;

memset(bmpData, 0, ImgSize());

}

void BMP::ReSize(int newW, int newH) {

biHeaderbiWidth = newW;

biHeaderbiHeight = newH;

biHeaderbiSizeImage = ImgSize();

if(bmpData!=NULL) delete[] bmpData;

bmpData = new unsigned char [biHeaderbiSizeImage];

Clear();

}

bool BMP::CreateImage(const BITMAPINFOHEADER &bih) {

memset(&biHeader,0,sizeof(BITMAPINFOHEADER));

delete[] bmpData;

bmpData = NULL;

memcpy(&biHeader, &bih, sizeof(BITMAPINFOHEADER));

biHeaderbiSizeImage = ImgSize();

bmpData = new unsigned char [ biHeaderbiSizeImage ];

if(bmpData == NULL) return false;

else{

Clear();

return true;

}

}

每次请求都把数据库中存放访问次数的值加一,或者是存在文件里的。

在输出时你可以先做0-9 10个数字的,然后在页面中显示

如果是10次 <img src="1png"><img src="0png"> 布局调一下就可以了。

以上就是关于一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值全部的内容,包括:一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值、c# 数字图象处理24位转8位并标记计数出现了问题,急!、用ASP.NET编写一个访问器数据,并使用图片的样式显示计数器等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9803947.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存