如何仅通过矩阵运算将jpg文件转换为pbm文件?
我尝试过如下的方法,但效果不是那么好。
for i = 1:h
for j = 1:w
Img(1,(i-1)*aligned_w+j) = (Matrix(i,j)&1);
%fwrite(file,1-Matrix(i,j),'ubit1');
end
for j = 1:align
%fwrite(file,0,'ubit1');
Img(1,(i-1)*aligned_w+w+j)=0;
end
end
fwrite(file,Img,'ubit1');
与 imwrite(imread('.jpg','jpg'),'.pbm','pbm') 相比,上面代码的结果偏离了轨道,任何人都可以告诉我如何解决它。
I have tried the method as follows, but it didn't work so efficient.
for i = 1:h
for j = 1:w
Img(1,(i-1)*aligned_w+j) = (Matrix(i,j)&1);
%fwrite(file,1-Matrix(i,j),'ubit1');
end
for j = 1:align
%fwrite(file,0,'ubit1');
Img(1,(i-1)*aligned_w+w+j)=0;
end
end
fwrite(file,Img,'ubit1');
the result of above code is off track compared to the imwrite(imread('.jpg','jpg'),'.pbm','pbm'), can anyone tell me how to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案,原因是 Matrix 应该是一个 wh 通道矩阵,格式 (i,j) 应该替换为 (i,j,channel),其中通道从 1 到3. 结果应该是或运算下的三个表达式。
I'm found the solution, the reason is that Matrix should be a whchannel matrix, the format (i,j) should be replaced into (i,j,channel), where channel from 1 to 3. And the result should be the three expression under or operation.