使用Qt框架编写的一个支持课程提供的.raw格式16位灰度图操作的图像处理器,自定义Image类型,封装几何变换、灰度映射、图像增强等功能,可以多步撤回及多图切换,附加一个比较简单的伪彩色图生成。
感谢C提供的按行读取图像方法;感谢L提供的完美的拉普拉斯滤波。
一、交互界面设计
(……具体ui设计待编辑ing,左边是一个缩略图栏,listwidget+Qicon,切换式功能栏借鉴室友刘某,但是给自己挖了大坑orz,比较多逻辑没有考虑清楚的……
1.取消撤回没有实现……
2.右键icon删除没做……
3.双击放大没做,现在的label太小了,即使有scroll也很不友好)
2022.11.19更新:
增加了伪彩色图生成。
二、自定义图像类型Image
类成员模仿QImage。
#ifndef IMAGE_H
#define IMAGE_H
#include<QImage>
#include<QPixmap>
#include<QLabel>
#include<complex>
#include <QtMath>
#include<QtGlobal>
class Image:public QImage
{
public:
enum format{
GRAY8,
GRAY16,
RGB32
};
Image();
~Image();
Image(const Image &image);//拷贝构造
Image(QString);//Qimage转换
Image(unsigned char* data,int width,int height,enum format fmt);
Image(unsigned short* data,int width,int height,enum format fmt);
Image* OpenFile_Gray16(QString FileName);//自定义文件格式读取
void SaveFile(QString FileName);//自选文件格式保存
QImage* convert(Image*);
Image* Rotate();//旋转
Image* Scaling();//缩放
Image* Flip();//左右翻转
Image* Grayscale();//灰度映射
Image* GrayFlip();//灰度反转
Image* Enhance();//图像增强
QString getFileName();
int getWidth();
int getHeight();
double getScale();
void setFileName(QString fn);
void convertmatrix();
void convertpixel(uchar**);
void setRotationAngle(double);
void setRotationCenterX(int);
void setRotationCenterY(int);
void setScale(double);
void setWinCenter(int);
void setWinWidth(int);
uchar getmyPixel8(int x,int y);
ushort getmyPixel16(int x,int y);
format getmyformat();
protected:
/*基本参数*/
QString FileName;//文件名
int height=0;//图像高
int width=0;//图像宽
enum format myformat;//图像格式
uchar* pixels=nullptr;//8位图像数据指针
ushort* pixels16=nullptr;//16位图像数据指针
int ByteCount;// 一个像素所需的字节数
int BytesPerLine;//一行字节数
/*几何变换参数*/
double RotationAngle=0;//旋转角度,默认正向转0度
int RoCX=0;
int RoCY=0;//旋转中心
double Scale=1.0;//缩放比例,默认等比例
/*灰度映射*/
int WinCenter=0;