为什么图像处理结果 只有一半 ??
#include "stdafx.h"
#include <highgui.h>
int main(int argc, char** argv)
{
//循环参数
int x, y;
// 像素值
double result;
uchar pixel[4];
//声明IplImage指针
IplImage* savepFrame = NULL;
IplImage *change = NULL;
//创建窗口
cvNamedWindow("原图", 1);
cvNamedWindow("增强",1);
//使窗口有序排列
cvMoveWindow("原图", 30, 0);
cvMoveWindow("增强", 420, 0);
savepFrame = cvLoadImage("flower.jpg",CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
change = cvCreateImage( cvSize( savepFrame->width, savepFrame->height ), savepFrame->depth, savepFrame->nChannels );
cvSet( change,cvScalarAll( 255 ), 0 );
for( y = 0; y < savepFrame->height - 1; ++y )
{
for( x = 0; x < savepFrame->width - 1; ++x )
{
pixel[0] = ((uchar*)( savepFrame->imageData +savepFrame->widthStep * y ))[ x ];
pixel[1] = ((uchar*)(savepFrame->imageData + savepFrame->widthStep * y ))[ x + 1 ];
pixel[2] = ((uchar*)( savepFrame->imageData +savepFrame->widthStep * ( y + 1 ) ))[ x ];
pixel[3] = ((uchar*)( savepFrame->imageData + savepFrame->widthStep * ( y + 1 ) ))[ x + 1 ];
result = sqrt(( pixel[0] - pixel[3] )*( pixel[0] - pixel[3] ) + ( pixel[1] - pixel[2] )*( pixel[1] - pixel[2] ));
((uchar*)(change->imageData + change->widthStep * y ))[x] = (uchar)result;
}
}
cvShowImage("原图", savepFrame); //原图
cvShowImage("增强", change); //增强后的图片
cvWaitKey(0);
//销毁窗口
cvDestroyWindow("原图");
cvDestroyWindow("增强");
return 0;
}
问:原图显示还正常,可是增强后的图就~~~变成一部分了。大概是3分之一。