Code Error?

Hi, I'm new in Matlab and I've problem in running this code below, can anyone tell me how to solve the problem? And also, where to put in the image? Thanks a lot:)
[EDITED: Code copied from Matlab toolbox function deleted, Jan S]
% Skip NaN check here; it will be done by imreconstruct if input
% is double.
[EDITED: Code formatted, Jan S]

6 Comments

Jan
Jan on 4 May 2012
Please format your code and use meaningful tags. Thanks.
You forgot to mention which problem you have. Do you get an error message, if so, which one and wehere? Or do the results differ from your expectations, and if so, how?
Superb
Superb on 4 May 2012
Hi, I have error (red line) in here, making it not allow to run at all.
function [im,conn] = parse_inputs(varargin)
And what do you mean by format? Is that tag not about "Matlab"?
I'm new in this forum, sorry :)
Daniel Shub
Daniel Shub on 4 May 2012
This is a clear case of copyright infringement. This code has been copied from the imclearborder function in the IPT.
Jan
Jan on 4 May 2012
*All* questions in this forum concern "Matlab", and only some theoretical questions do not concern "Matlab code". Therefore the tag "Matlab code" is not sufficient to classify the question. See http://www.mathworks.com/matlabcentral/answers/33319-is-matlab-or-matlab-code-a-useful-tag
Please follow the "Markup help" link on this page for an introduction in formatting messages in this forum. Further good tips are found at:
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Superb
Superb on 4 May 2012
Hi, thanks for the guide on tag :)
Daniel, is that we can't check it? I need this as I need to do my homework for the conversion of code, since other code we don't have imclearborder, so that's the only solution I have, sorry :(
Jan
Jan on 4 May 2012
Please, Superb, do not post copyright protected code. This conflicts with the license conditions you have accepted, while you have installed Matlab. You can use the code and modify copies of Matlab's toolbox functions, but you cannot copy it. And do not forget to mention the author of the code, when you submit it as homework.

Sign in to comment.

Answers (1)

Jan
Jan on 4 May 2012

0 votes

You cannot define a function inside a script. The differences between functions and scripts are explained in the documentation. An easy solution is to convert the M-file to a function by starting it with the term "function" and define for the inputs and outputs as arguments.

11 Comments

Superb
Superb on 4 May 2012
Ok, thanks, I get it, so how to input an image now after I have the "function" at the top? Thanks :)
Jan
Jan on 4 May 2012
I have to guess what you want. It is *not*, that you have a painting on paper and want to scan it.
But I cannot guess how you have your "image" represented: As file name, imported by IMREAD or a live picture from a web cam?
Are you asking for the way to define inputs and outputs of a function? While you can see a lot of examples in Matlab's toolbox functions, it is explained in general in the Getting Started chapters of the documentation.
Superb
Superb on 4 May 2012
I want to get from imread, so I do like this,
function im2 = imclearborder(varargin)
I=imread('21.jpg');
bw=im2bw(I);
figure, imshow(bw);
[im,conn] = parse_inputs(varargin{:});
.
.
.
.
.
.
end
So, my question is how to put my "bw", so that it can pass through the function? And lastly, I will make it show out using imshow after the function, thanks :)
Walter Roberson
Walter Roberson on 4 May 2012
Do not put those three lines inside the imclearborder() routine. Leave imclearborder() completely unchanged (not a copy.) Then in a _different_ .m file, put the lines
I=imread('21.jpg');
bw=im2bw(I);
figure, imshow(bw);
newbw = imclearborder(bw);
figure, imshow(newbw);
Superb
Superb on 4 May 2012
Thanks Walter,
I tried your method but I noticed that it actually run the predefined function "imclearborder" in Matlab.
So I decided to change this function
im2 = imclearborder(varargin)
to
function im2 = abc(varargin)
and save as abc.m
then again i used
I=imread('21.jpg');
bw=im2bw(I);
figure, imshow(bw);
newbw = abc(bw);
figure, imshow(newbw);
Now it doesn't work, may I know any mistake I did here?
ERROR:
??? Undefined function or method 'conn2array' for input arguments of type
'double'.
Error in ==> abc at 4
conn = conn2array(conn);
Error in ==> asd at 4
newbw = abc(bw);
Thanks :)
Walter Roberson
Walter Roberson on 4 May 2012
conn2array() is a method that is specific to the "image" object class, and cannot be accessed from outside of that.
I do not understand why you are wanting to use a modified imclearborder() rather than using the built-in one?
Superb
Superb on 5 May 2012
My project is to convert the Matlab code into OpenCV, so I don't have the equivalent in OpenCV for imclearborder, so I have to know how's the imclearborder comes from, thanks for understanding :)
Daniel Shub
Daniel Shub on 5 May 2012
Converting copyright MATLAB code into OpenCV seems to be a direct violation of the MATLAB EULA.
Superb
Superb on 5 May 2012
Then, can anyone tell me how to convert? Thanks a lot :)
Jan
Jan on 5 May 2012
@Superb: Either you reprogram the function from scratch by your own, or you pay somebody to do this for you. But copying or "converting" copyrighted code is not an option.
You will not get assistance for stealing Matlab code in this forum.
Superb
Superb on 6 May 2012
Ok, thanks, now I understand it, thanks for info :)

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Asked:

on 4 May 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!