【发布时间】:2016-08-11 11:18:45
【问题描述】:
我正在做一个家庭作业,我们得到了一个包含灰度图像数据的 .bin 文件。这里的目标是编写 C 代码,将其从灰度转换为二进制图像。首先是在 MATLAB 中打开灰度图像,我设法通过以下方式完成:
A = fread(file, 256*256, 'uint8=>uint8');
A = reshape(A, 256, 256).';
imshow(A);
太好了。我有我的图像系数,我将其分成 4 个数组并填充到 C 头文件中。我必须这样做,因为我们用于此类的微控制器 - MSP430 - 无法一次处理所有这些。我导入了第一个头文件,设置了我的变量,所有繁重的工作都在这里完成:
for (i = 0; i == 16384; i++){
if (suzi[i] >= 95){ //95 is given threshhold
temp = 0b0000000;
}
else{
temp = 0b00000001 << shiftby; //will right shift by 7, then 6, then 5 until 0 and then wrap back to 7
}
current = previous | temp; //updates the 8 bit data with the latest bit
if(shiftby > 0){
shiftby--; //decrements shifts until 0
}
else{
shiftby = 7; //wraps back to 7
suziarr[arrayindex] &= 0b00000000; //makes sure this value is 8 0s
suziarr[arrayindex] |= current; //sets bits to match current 8 bit value
current = 0b00000000;
arrayindex++; //this is why the array will be 1/8 the size
}
previous = current; //update state
}
temp、suzi、suziarr、previous 和 current 变量被声明为 unsigned char 类型。 suzi 也是一个常量,是我塞进头文件的数组之一。 suzi 的长度设置为 13684,而 suziarr 的长度设置为 2048。无论出于何种原因,无论我使用 4 组数据中的哪一组,我都会得到完全相同的数字,所以这里出了点问题。我错过了什么?
【问题讨论】:
标签: c image matlab image-processing