Thread Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Marcus

Date: 13 Dec, 2011 11:37:08

Message: 1 of 8

Hey there,

I guess my biggest Problem is that I am a total Simulink novice. For the last week I am trying to read an image in a Simulink block. First, I thought I just create an embedded Matlab function using the "imread" command like it is possible in Matlab. But this is not working in Simulink.
I also don t have the Video and Image Processing Blockset (so no "read image from file" block), but I guess that is exactly what I am searching for.

In S-Function Examples (see User-defined Functions) there is an example on how to load a video from a .mat-file in a block. I have tried to modify this block to fit my purpose, no success.

I would be grateful for any advice
Marcus

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Phil Goddard

Date: 13 Dec, 2011 11:51:08

Message: 2 of 8

Did you define imread to be eml.extrinsic?

Phil.

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Marcus

Date: 13 Dec, 2011 12:37:08

Message: 3 of 8

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jc7e7c$k3t$1@newscl01ah.mathworks.com>...
> Did you define imread to be eml.extrinsic?
>
> Phil.

Are u referring to me using a "Matlab embedded Fcn"- Block and then "evaluating" the imread command?

Marcus

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Phil Goddard

Date: 13 Dec, 2011 12:41:08

Message: 4 of 8

Yes.

Phil.

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: witek@mathworks.com

Date: 13 Dec, 2011 12:49:58

Message: 5 of 8

Try this page:

http://www.mathworks.com/help/toolbox/simulink/ug/bsoywg7.html

and search for "extrinsic" within this page.

Witek

Marcus <m.futterlieb@tu-bs.de> wrote:
> "Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jc7e7c$k3t$1@newscl01ah.mathworks.com>...
> > Did you define imread to be eml.extrinsic?
> >
> > Phil.
>
> Are u referring to me using a "Matlab embedded Fcn"- Block and then "evaluating" the imread command?
>
> Marcus

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Marcus

Date: 13 Dec, 2011 13:46:08

Message: 6 of 8

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jc7h54$sh0$1@newscl01ah.mathworks.com>...
> Yes.
>
> Phil.

Hey Phil,

so this is what i got:
%------------------------------------------------Matlab embedded fcn block---

function y = fcn(u)
%#eml


x = 'imread(''test.jpg'',''jpg'')';
eml.extrinsic('eval');
a = eval (x);


y = u*a;

%----------------------------------------------------------------------------------------

u is just a constant (1) and I would like to output the picture through y but Matlab is giving me this error:
***Function output 'y' cannot be of MATLAB type***
So does this will never work? Or am I missing something?

Thanks Phil, and Witek, I ll have a look at your link right now
Marcus

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Phil Goddard

Date: 14 Dec, 2011 07:06:08

Message: 7 of 8

I'm not sure why you wouldn't just do

eml.extrinsic('imread');
y = u*imread('test.jpg','jpg');

But that's not likely the cause of the problem.

I suspect the issue is that you haven't preallocated the size of y and hence the code won't compile.
If you know in advance the size of the output then you can put something like zeros(n,m) at the top to do the preallocation.
If not, then you'll need to define the output as being variable sized:
http://www.mathworks.com.au/help/toolbox/simulink/ug/br9_55w.html

Phil.

Subject: Load picture in a Simulink (2lvl Mathlab Fcn) block

From: Marcus

Date: 14 Dec, 2011 08:37:08

Message: 8 of 8

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jc9ht0$q15$1@newscl01ah.mathworks.com>...
> I'm not sure why you wouldn't just do
>
> eml.extrinsic('imread');
> y = u*imread('test.jpg','jpg');
>
> But that's not likely the cause of the problem.
>
> I suspect the issue is that you haven't preallocated the size of y and hence the code won't compile.
> If you know in advance the size of the output then you can put something like zeros(n,m) at the top to do the preallocation.
> If not, then you'll need to define the output as being variable sized:
> http://www.mathworks.com.au/help/toolbox/simulink/ug/br9_55w.html
>
> Phil.

Alright guys,

It is working now, thanks for the help, if anyone is interested this is what I did:

***for the load function block I deleted the input and set the size for the output to [256 256] (right click the block and go to explore) uint8 (grayscale picture).
--------------------------------------------------------------------------------------------------
function y =load
%#eml

x = 'imread(''test.jpg'',''jpg'')';
eml.extrinsic('eval');
y=zeros(256,256,'uint8');
y = eval (x);
---------------------------------------------------------------------------------------------------

***for the display function block I deleted the output and set the size for the input to [256 256] uint8
--------------------------------------------------------------------------------------------------
function display(u)
%#eml
eml.extrinsic('imshow');
imshow(u)
---------------------------------------------------------------------------------------------------

Thanks again for the help :)
Marcus

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
simulink load r... Marcus 13 Dec, 2011 06:39:12
rssFeed for this Thread

Contact us at files@mathworks.com