help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting a Matlab program to Octave


From: Terry Duell
Subject: Re: Converting a Matlab program to Octave
Date: Thu, 03 Jul 2014 14:41:33 +1000
User-agent: Opera Mail/12.16 (Linux)

On Thu, 03 Jul 2014 13:48:18 +1000, Terry Duell <address@hidden> wrote:

On Thu, 03 Jul 2014 12:03:47 +1000, momozilla76 <address@hidden>

[snip]


can someone please help me

The function would be used the same way in Octave as in Matlab.
As the error message implies, you need to assign, or define the parameters/variables (a,W,noShow) in your calling function or script before calling the function adaptiveThres(). If you think you have done that, it would be helpful to include sufficient of the calling function or script so we can see how these variables are being defined.


Further to the above, is the code of the function adaptiveThres(), which you provided complete? Here is a minor modification to that code, along with some lines to show how it would be called, save this as "test.m" or whatever you like in the same dir as adaptiveThres(), and then in a terminal window "octave test.m". You will need the image package from octave forge to have access to the imread function.

%% check adaptiveThres function
%% read in image
im = imread("IMGP1453.JPG");
% get the first band (it is an RGB, adaptiveThres only expects 1 band)
a = im(:,:,1);
o = adaptiveThres(a,100);
pause

function [o] = adaptiveThres(a,W,noShow);
%Adaptive thresholding is performed by segmenting image a
[w,h] = size(a);
o = zeros(w,h);
%seperate it to W block
%step to w with step length W
for i=1:W:w
for j=1:W:h
mean_thres = 0;
if i+W-1 <= w & j+W-1 <= h
 mean_thres = mean2(a(i:i+W-1,j:j+W-1));
%% mean_thres = 0.8*mean_thres; 57 %% the 57 here makes no sense, it is simply printed to screen each iteration
 mean_thres = 0.8*mean_thres;
 o(i:i+W-1,j:j+W-1) = a(i:i+W-1,j:j+W-1) < mean_thres;
 end;
 end;
end;
if nargin == 2
imagesc(o);
colormap(gray);
end;

Hope that helps,

Cheers,
--
Regards,
Terry Duell



reply via email to

[Prev in Thread] Current Thread [Next in Thread]