Python Forum
Help converting MATLAB triple-for loop to Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help converting MATLAB triple-for loop to Python
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting python to FileMaker DWolf 6 1,685 Sep-22-2022, 03:40 AM
Last Post: DWolf
Photo Matlab to Python Sateesh 0 1,673 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 2,001 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 2,189 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  EOF while scanning triple-quoted string literal louis216 1 3,931 Jun-30-2020, 04:11 AM
Last Post: bowlofred
  Matlab to Python -- Parallel Computing zistambo 1 1,967 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 3,025 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 3,873 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,448 Mar-25-2020, 10:14 PM
Last Post: j.crater
  MATLAB to Python conversion stokd 10 5,009 Jan-19-2020, 09:14 PM
Last Post: stokd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020