Python Forum

Full Version: Help converting MATLAB triple-for loop to Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have the following code in MATLAB which I am trying to convert to python, using numpy.

M = zeros(100,100); imageFiles = dir('*.bmp'); nFiles = length(imageFiles); for i = 1:nFiles currentFilename = imageFiles(i).name; f1 = fopen(num2str(currentFilename),'rb'); fread(f1,13,'char'); im = fread(f1,100*100,'uint8'); %currentImage = imread(currentFilename); %im = currentImage; for k = 1:100 for m = 1:100 NIM(i,k,m) = im((k-1)*100+m); end end fclose(f1); end
I'm unfamiliar with how to load a 3D matrix in python. Any help would be greatly appreciated.
I don't think you need to load '*.bmp' content manually in Python. Take a look at scikit-image package. skimage.io.imread returns 3D numpy array, if the file was successfully read.