How I can read image with PPM format without imread and design PPM reader ?
Show older comments
I want to read test.ppm image without imread and design PPM reader and open it with fopen and extract data from it after that show it with imshow.
Can you help me?
7 Comments
DGM
on 25 Nov 2021
Find the format specification:
Read the file with fread() or something
split the header, etc from the raster data
based on the information in the header, do whatever needs to be done to convert the raster data into a MxNx3 numeric array.
elma ozge
on 26 Nov 2021
Image Analyst
on 26 Nov 2021
Why do you not want to use the built-in imread() and try to write your own ppm reader (or actually have us write it for you)? What's wrong with using imread()????
elma ozge
on 26 Nov 2021
Image Analyst
on 26 Nov 2021
We know that. You already said that earlier. I was curious as to why.
And DGM already gave you a start, so just continue on with that. You accepted it (thanks), so I guess that's what you're planning on.
elma ozge
on 26 Nov 2021
Walter Roberson
on 26 Nov 2021
What is the reason that you cannot use imread() ?
Accepted Answer
More Answers (2)
Walter Roberson
on 25 Nov 2021
1 vote
fopen the file and read it as a series of uint8. fclose(). Now use loadlibrary() to make a call to the libnetpbm library to decode the uint8 into an image.
By the way, is it a P3 or P6?
2 Comments
elma ozge
on 26 Nov 2021
Walter Roberson
on 26 Nov 2021
PPM files do not all have exactly the same layout. The very first item inside a PPM file gives information about which of the formats the rest of the file is in. Two of the most common formats are known by the codes P3 and P6.
If you need to be able to handle all possible PPM files, then you have to do notably more work than if you only have to handle one particular kind of PPM file.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!