写程序 图像处理
2012-04-01 22:14:43 whucv 阅读数 893
源代码链接
// Image.h: interface for the CImage class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_)
#define AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
using namespace std; //使用标准库,必须添加命名空间
struct SLineInfo
{
	int Angle;
	int Dist;
	int Pixels;
	
};

class CImage  
{
public:
	double CalCorrelation(unsigned char*pBase,unsigned char*pSamp,int nBlockLen);
	CString ImageName;
	void InCircle(vector<CPoint>&Polygon,vector<SLineInfo>&Lines,double&R,CPoint¢er);
	double CalRadius(CPoint point,vector<SLineInfo>&LineInfo);
	double Point2Line(CPoint point,SLineInfo Line);
	BOOL HoughLines(vector<SLineInfo> &LineInfo,int nLineRet,unsigned char*img,int nwidth,int nheight);
	CPoint CenterPoint(vector<CPoint>& VectorPoint);
	bool TraceEdge(vector<CPoint>&VectorPoint);
	BOOL TraceEdge(unsigned char*lpSrc,int nwidht,int nheight);
	void MedianFilter();
	int size;
	void toBinary(unsigned char *lpSrc,int nwidth,int nheight,int nthread);
	unsigned char* BinToRgb(unsigned char *lpSrc, int nWidth, int nHeight);
	unsigned char* RgbToBin(unsigned char *lpSrc, int nWidth, int nHeight);
	void SelectArea(CPoint ptStart,CPoint ptEnd);
	void SelectArea(vector<CPoint>Polygon);
	
	BOOL Backup();
	unsigned char* backbuffer;//备份数据
	void GaussianSmooth(double sigma);
	BOOL toBW(int Thread);
	BOOL SaveBMP(LPCTSTR bmpName, unsigned char *imgBuf, int width, int height,int biBitCount, RGBQUAD *pColorTable);
	BOOL SaveBMP(LPCTSTR lpszPathName);
	void DrawHis(CDC*pDC);
	void CalHis(unsigned char*pBits,int nWidth,int nHeight,LONG data[],int nLength);
	LONG Min(LONG data[],int nLength,int &id);
	LONG Max(LONG data[],int nLength,int &id);
	void DrawGraph(CDC *pDC,SIZE sz,LONG data[],int nLength,CString name);
	BOOL Canny(double sigma,double dRatioLow,double dRatioHigh);
	void Template(unsigned char *lpDIBBits, LONG lWidth, LONG lHeight, int iTempH, int iTempW, FLOAT *fpArray, FLOAT fCoef);
	void Canny(LPBYTE pGray, SIZE sz, double sigma, double dRatLow, double dRatHigh, LPBYTE pResult);
	void TraceEdge(int y, int x, int nThrLow, LPBYTE pResult, int *pMag, SIZE sz);
	void Hysteresis(int *pMag, SIZE sz, double dRatLow, double dRatHigh, LPBYTE pResult);
	void EstimateThreshold(int *pMag, SIZE sz, int *pThrHigh, int *pThrLow, LPBYTE pGray,double dRatHigh, double dRatLow);
	void NonmaxSuppress(int *pMag, int *pGradX, int *pGradY, SIZE sz, LPBYTE pNSRst);
	void Grad(SIZE sz, LPBYTE pGray,int *pGradX, int *pGradY, int *pMag);
	void GaussianSmooth(SIZE sz, LPBYTE pGray, LPBYTE pResult, double sigma);
	void CreatGauss(double sigma, double **pdKernel, int *pnWidowSize);
	BOOL ReadBMP(LPCTSTR lpszPathName);
	int openMode;//
	BITMAPFILEHEADER bmpFH;
	int colorBits;// 位数8 24
	int width;
	int height;
	RGBQUAD* palette;//颜色表指针
	unsigned char* imageData;//数据指针
	BITMAPINFOHEADER* bmpIH;
	BITMAPINFO* bmpInfo;
	CImage();

	virtual ~CImage();

protected:
	unsigned int *buffer;
};

#endif // !defined(AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_)


2012-04-01 22:14:00 iteye_6233 阅读数 9
源代码链接
// Image.h: interface for the CImage class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_)
#define AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
using namespace std; //使用标准库,必须添加命名空间
struct SLineInfo
{
	int Angle;
	int Dist;
	int Pixels;
	
};

class CImage  
{
public:
	double CalCorrelation(unsigned char*pBase,unsigned char*pSamp,int nBlockLen);
	CString ImageName;
	void InCircle(vector<CPoint>&Polygon,vector<SLineInfo>&Lines,double&R,CPoint¢er);
	double CalRadius(CPoint point,vector<SLineInfo>&LineInfo);
	double Point2Line(CPoint point,SLineInfo Line);
	BOOL HoughLines(vector<SLineInfo> &LineInfo,int nLineRet,unsigned char*img,int nwidth,int nheight);
	CPoint CenterPoint(vector<CPoint>& VectorPoint);
	bool TraceEdge(vector<CPoint>&VectorPoint);
	BOOL TraceEdge(unsigned char*lpSrc,int nwidht,int nheight);
	void MedianFilter();
	int size;
	void toBinary(unsigned char *lpSrc,int nwidth,int nheight,int nthread);
	unsigned char* BinToRgb(unsigned char *lpSrc, int nWidth, int nHeight);
	unsigned char* RgbToBin(unsigned char *lpSrc, int nWidth, int nHeight);
	void SelectArea(CPoint ptStart,CPoint ptEnd);
	void SelectArea(vector<CPoint>Polygon);
	
	BOOL Backup();
	unsigned char* backbuffer;//备份数据
	void GaussianSmooth(double sigma);
	BOOL toBW(int Thread);
	BOOL SaveBMP(LPCTSTR bmpName, unsigned char *imgBuf, int width, int height,int biBitCount, RGBQUAD *pColorTable);
	BOOL SaveBMP(LPCTSTR lpszPathName);
	void DrawHis(CDC*pDC);
	void CalHis(unsigned char*pBits,int nWidth,int nHeight,LONG data[],int nLength);
	LONG Min(LONG data[],int nLength,int &id);
	LONG Max(LONG data[],int nLength,int &id);
	void DrawGraph(CDC *pDC,SIZE sz,LONG data[],int nLength,CString name);
	BOOL Canny(double sigma,double dRatioLow,double dRatioHigh);
	void Template(unsigned char *lpDIBBits, LONG lWidth, LONG lHeight, int iTempH, int iTempW, FLOAT *fpArray, FLOAT fCoef);
	void Canny(LPBYTE pGray, SIZE sz, double sigma, double dRatLow, double dRatHigh, LPBYTE pResult);
	void TraceEdge(int y, int x, int nThrLow, LPBYTE pResult, int *pMag, SIZE sz);
	void Hysteresis(int *pMag, SIZE sz, double dRatLow, double dRatHigh, LPBYTE pResult);
	void EstimateThreshold(int *pMag, SIZE sz, int *pThrHigh, int *pThrLow, LPBYTE pGray,double dRatHigh, double dRatLow);
	void NonmaxSuppress(int *pMag, int *pGradX, int *pGradY, SIZE sz, LPBYTE pNSRst);
	void Grad(SIZE sz, LPBYTE pGray,int *pGradX, int *pGradY, int *pMag);
	void GaussianSmooth(SIZE sz, LPBYTE pGray, LPBYTE pResult, double sigma);
	void CreatGauss(double sigma, double **pdKernel, int *pnWidowSize);
	BOOL ReadBMP(LPCTSTR lpszPathName);
	int openMode;//
	BITMAPFILEHEADER bmpFH;
	int colorBits;// 位数8 24
	int width;
	int height;
	RGBQUAD* palette;//颜色表指针
	unsigned char* imageData;//数据指针
	BITMAPINFOHEADER* bmpIH;
	BITMAPINFO* bmpInfo;
	CImage();

	virtual ~CImage();

protected:
	unsigned int *buffer;
};

#endif // !defined(AFX_IMAGE_H__294B5F7A_8973_4F4D_9AB6_19EB14061FD4__INCLUDED_)


2016-01-28 15:30:30 feitianziyouaoxiang 阅读数 340
%% load image data
pic3=imread('pic3.jpg');
pic2=imread('pic2.jpg');

%% resize pic
pic31=imresize(pic3,[340 430]);
pic21=imresize(pic2,[340 430]);

%% display pic11
image(pic31);
axis equal; axis off;

%% display pic21
image(pic21);
axis equal; axis off;

%% scale and display pic
duller=0.5*pic21;
image(duller);
axis equal; axis off;

%% add the pic 
combined=pic31+duller;
image(combined);
axis equal; axis off;

%% save the combined picture as type of BMP
imwrite(combined,'combined_picture.bmp','bmp');
2017-03-24 09:42:08 Eric_Blog_CSDN 阅读数 623

1、在计算图像局部窗口统计分布时应用了一次积分和二次积分图像,计算效率大幅提高。


2、对每个像素都是基于局部窗口的统计特性,逐一进行灰度值的调整,能够较好地显示当前像素和周围的对比关系,对场景有很好适应性。


3、一次积分是指:  ID+IA-IB-IC

2018-07-29 20:52:21 qq_40605167 阅读数 177
import numpy as np
from PIL import Image

if __name__ == '__main__':
    image_file = '3.jpg'
    height = 100
    img = Image.open(image_file)
    img_width, img_height = img.size
    width = 2 * height * img_width // img_height    # 假定字符的高度是宽度的2倍
    img = img.resize((width, height), Image.ANTIALIAS)  #图片反编码
    pixels = np.array(img.convert('L')) # 不同模式图像之间的转换
    print(pixels.shape)
    print(pixels)
    chars = "MNHQ$OC?7>!:-;. "
    N = len(chars)
    step = 256 // N
    print(N)
    result = ''
    for i in range(height):
        for j in range(width):
            result += chars[pixels[i][j] // step]
        result += '\n'
    with open('text2.txt', mode='w') as f:
        f.write(result)
没有更多推荐了,返回首页