我正在做作业,我们得到了一个.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也是一个const,是我塞入头文件中的数组之一。 suzi的长度设置为13684,而suziarr的长度设置为2048。无论出于何种原因,无论我使用的是4组数据中的哪一组,我都得到完全相同的数字,所以这里有些错误。我想念什么?
最佳答案
循环
for (i = 0; i == 16384; i++)
不会重复。它应该是
for (i = 0; i < 16384; i++)