MATLAB Answers

Is there a way to read a .pf file also known as picture floatmap file?

10 views (last 30 days)
Hello, I am new to matlab and I am trying to open and visualize a .pf file as image but I was unable to do so. Is there a way to read .pf file and visualize it as a image.
I link fot the pf file As for the file I cannot see or oopen it.
Any help is appreciated and Thank you so much in advance.
Aravind Poolla
Aravind Poolla on 26 Mar 2021
Hello I dont know from which software the file is from but all I know is it is a measurement file.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 26 Mar 2021
Edited: Cris LaPierre on 26 Mar 2021
I found this document, which suggests your file is not a valid pfm file.
  • The PFM header is 3 consecutive "lines" of ASCII text. Your file has 5 lines
  • The identifier line contains the characters "PF" or "Pf". PF means it's a color PFM. Pf means it's a grayscale PFM. You don't appear to have this line.
  • The dimensions line contains two positive decimal integers, separated by a blank. The first is the width of the image; the second is the height. Both are in pixels. You file places the values on separate lines.
  • The Scale Factor / Endianness line indicates if the numbers are stored in little endian or big endian format. Your file doesn't have this line.
However, with that information, it is possible to turn it into a valid pfm file format and use the function Walter pointed to to load it. BTW, your file uses big endian format. So you just need to replace your header
  • Typ=Pic98::TPlane<float>
  • Lines=750
  • Columns=1125
  • FirstLine=0
  • FirstColumn=0
With a valid header. I didn't know the scale factor so I used 1.
  • Pf
  • 1125 750
  • s1
Once you've made those changes to your file, you can load and visualize it with the following code. I've attached your file updated to a pfm format. I had to change the extension to txt to be able to attach it here.
img = read_pfm("PF_file.txt", false)

More Answers (1)

Walter Roberson
Walter Roberson on 26 Mar 2021
Edited: Walter Roberson on 26 Mar 2021
Walter Roberson
Walter Roberson on 26 Mar 2021
As suspected, you failed to quote the file name.
img = read_pfm('simulation.pfm', 'bPhotoshopCompatibility')

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by