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
  Media Pipe Python Interfacing with MATLAB cmcreecc 1 1,501 May-30-2024, 07:23 AM
Last Post: TrentErnser
  Regex to find triple characters bfallert 14 4,935 May-16-2024, 04:02 PM
Last Post: xMaxrayx
  Converting python to FileMaker DWolf 6 4,090 Sep-22-2022, 03:40 AM
Last Post: DWolf
Photo Matlab to Python Sateesh 0 2,493 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 3,110 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 3,448 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  EOF while scanning triple-quoted string literal louis216 1 6,007 Jun-30-2020, 04:11 AM
Last Post: bowlofred
  Matlab to Python -- Parallel Computing zistambo 1 3,279 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 5,551 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 5,434 Apr-02-2020, 10:29 PM
Last Post: chai0404

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.