#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#define SIZE_X 256
#define SIZE_Y 256
using namespace std;
struct vectorStruct {
int value;
int point_x;
int point_y;
bool operator<(const vectorStruct& abc)const
//compare function
{
return value < abc.value;
}
};
int main()
{
int c;
int count = 1;
vector<int> sortArr;
int minSort;
float imgWeight, imgHeight;
// 0 ~ 255
unsigned char arr[SIZE_X][SIZE_Y];
unsigned char img[SIZE_X][SIZE_Y] = { { 0, }, };
FILE *fp;
std::vector<vectorStruct> minVector;
vectorStruct vectorStruct;
if ((fp = fopen("C:/Users/user/Documents/Visual Studio 2015/Projects/ExtracingImg/lena.raw", "rb")) == NULL) {
perror;
return -1;
}
fread(img, 1, SIZE_Y * SIZE_X, fp);
fclose(fp);
for (int y = 1; y < SIZE_Y - 1; y++) {
for (int x = 1; x < SIZE_X - 1; x++) {
imgWeight = img[y - 1][x + 1] // (0, 2)
- img[y - 1][x - 1] // (0, 0)
+ 2 * (img[y][x + 1] - img[y][x - 1]) // 2 * (1,2) - (1,0)
+ img[y + 1][x + 1] // (2, 2)
- img[y + 1][x - 1]; // (2, 0)
imgHeight = img[y - 1][x - 1] // (0,0)
- img[y + 1][x - 1] // (2, 0)
+ 2 * (img[y - 1][x] - img[y + 1][x]) // 2 * (0, 1) - (2, 0)
+ img[y - 1][x + 1] // (0 , 2)
- img[y + 1][x + 1]; // (2, 2)
c = (int)sqrt(imgHeight * imgHeight + imgWeight * imgWeight);
if (c > 255) c = 255;
arr[y][x] = c;
}
}
for (int x = 1; x < SIZE_X - 1; x++)
{
for (int y = 1; y < SIZE_Y - 1; y++)
{
sortArr.push_back(arr[x - 1][y - 1]);
sortArr.push_back(arr[x - 1][y]);
sortArr.push_back(arr[x - 1][y + 1]);
sortArr.push_back(arr[x][y - 1]);
sortArr.push_back(arr[x][y]);
sortArr.push_back(arr[x][y + 1]);
sortArr.push_back(arr[x + 1][y - 1]);
sortArr.push_back(arr[x + 1][y]);
sortArr.push_back(arr[x + 1][y + 1]);
auto iter = min_element(sortArr.begin(), sortArr.end());
if (arr[x][y] == *iter)
{
vectorStruct.value = arr[x][y];
vectorStruct.point_x = x;
vectorStruct.point_y = y;
minVector.push_back(vectorStruct);
}
sortArr.clear();
}
}
cout << minVector.size() << endl;
sort(minVector.begin(), minVector.end());
// value, x, y check
for (auto i : minVector)
{
std::cout << i.value << " " << i.point_x << " " << i.point_y << std::endl;
count++;
}
printf("%d", count);
return 0;
}
我尝试在将“ lena.raw”图像文件导入为数组之后,并通过提取最小值按升序排序。
在这段代码中,我在“调试x86”模式下计算了“ for(auto i:minVector)循环”计数值为5785
但在“发布x64”模式下计数值为5609
在这种情况下有什么区别?
你能告诉我为什么我有不同的价值吗?