Home > Back-end >  How can I convert jpg file to pbm file through only matrix operation?
How can I convert jpg file to pbm file through only matrix operation?

Time:03-04

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.

CodePudding user response:

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.

  • Related