Home > database >  explain uplaoding .RAW data images into the jupyter notebook?
explain uplaoding .RAW data images into the jupyter notebook?

Time:12-21

Greeting I know how to import .raw data images into the jupyter notebook but I don.t seem to understand the logic explanation.. Below is the code give, please explain these line to me in as simple way as possible

# Read input RAW file
raw_file = np.fromfile('Sandstones/' name '_2d25um_binary.raw', dtype=np.uint8)
im = (raw_file.reshape(1000,1000,1000))
im = im==0;

I tried alternate ways but this was the best as well as the preferred. I have run it but I don't seem to understand the last line

CodePudding user response:

name is some variable. Let's say it is name of your file. np.fromfile takes in a path, and the datatype it wants to read, and convert it into an array.

so

'Sandstones/' name '_2d25um_binary.raw'

is the path, if the name is file1 then it will be

'Sandstones/file1_2d25um_binary.raw'

You read this file into a numpy array which is a special data structure as uint8.

In the next line of code, you simply reshape the values you read from the file to a 3D array with the shape

1000, 1000, 1000

The last line changes the im array values. If you notice, im is your numpy array, All the values, which are equal to 0 will be changed to 1 as im==0 will be true, rest will be changed to false. You can think of these as a Boolean array of 0s and 1s where 1 are those number which were 0 in the original array. You can learn more about it here

  • Related