如何仅通过矩阵运算将jpg文件转换为pbm文件?

发布于 2025-01-10 04:58:16 字数 492 浏览 4 评论 0原文

我尝试过如下的方法,但效果不是那么好。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁虫ゝ 2025-01-17 04:58:16

我找到了解决方案,原因是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文