1

I'm trying to run matlab code in python.

For this reason, I installed the oct2py to read a .m script file from Spyder.

The script file (Enhance.m) contains some functions. When I try to invoke this script file, it returns:

Oct2PyError: Octave evaluation error:
error: invalid call to script C:\Users\melih\Fingerprint\Matlab_kod_deneme\Enhance.m error.

I tried to add my python current work space path to octave via this code but it didn't work:

oc.addpath(r"C:\Users\melih\Fingerprint\Matlab_kod_deneme")

This is my main python code :

from oct2py import Oct2Py
import cv2
from skimage import exposure
import numpy as np

oc = Oct2Py()
#oc.addpath(r"C:\Users\melih\Fingerprint\Matlab_kod_deneme")

img = cv2.imread('mehtap2.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = exposure.equalize_adapthist(img, clip_limit=0.03)
rows,cols = np.shape(img);
aspect_ratio = np.double(rows)/np.double(cols);

new_rows = 350;             # randomly selected number
new_cols = new_rows/aspect_ratio;

#img = cv2.resize(img,(new_rows,new_cols));
img = cv2.resize(img,(np.int(new_rows),np.int(new_cols)));

img = oc.Enhance(img)
img = oc.Enhance(img)
img = oc.Enhance(img)

and this is my Enhance.m script :

1; 
function [Enhimage] = Enhance(img)

%...some operations...

% it calls other functions within Enhance.m script file
Enhimage = enhimg;
end;
Examples of some functions that are inside Enhance.m script file
 ( they are called by Enhance function) : 

function y = raised_cosine(nBlkSz,nOvrlp)
%...some operations...
y(abs(x)<nBlkSz/2)=1;

end;

function w = raised_cosine_window(blksz,ovrlp)
y = raised_cosine(blksz,ovrlp);
w = y(:)*y(:)';
end;
melburmer
  • 11
  • 3
  • You called your script "Enhance". Call it something else, otherwise it coflicts with the "command-line" function of the same name defined _inside_ it. Having said that, avoid command-line functions if there's no real need for them. Create a bespoke file for your function of the same name and call it using that name. – Tasos Papastylianou Oct 28 '19 at 13:21
  • alternatively, calling your script using the `oc.run(` function might work, but even then, ignore the above advice at your peril. Name conflicts are rarely a good idea. – Tasos Papastylianou Oct 28 '19 at 13:22

0 Answers0