Discussion:
[Scilab-users] Put an image as the background of an axis
a***@laas.fr
2016-02-08 10:47:45 UTC
Permalink
Hi everyone,

I just failed at placing an image behind a plot.
I thought that would be easy:
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"

Apparently I was wrong.
I did not find a way to overlap a plot with transparent background over
my image.
It seems that the image is always above the plot no matter what order
the uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work either.

Any idea?
Jan Åge Langeland
2016-02-08 16:49:08 UTC
Permalink
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background
over my image.
It seems that the image is always above the plot no matter what order
the uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work either.
Any idea?
ShowImage(im,'J2');

b=newaxes(); b.filled = "off"; plot(a)


Post by a***@laas.fr
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Philipp Mühlmann
2016-02-08 23:04:17 UTC
Permalink
Well, as I understand you want to plot a function over an background image.

In the case the image pixel number fits the X-Y range of your graph it's
rather simple.

img = ReadImage(IPD_PATH + 'demos\teaset.png');
rows = size(img,'r');cols = size(img,'c');
img(rows,1,:) = (0); // changing left lower image corner for
checking purpose
// change all 3 colour
channels to get a black pixel
ShowColorImage(img,'');
a = gca();a.axes_visible = ["on","on","off"];x = linspace(1,600,600);y
= 1/2*(x);plot(x,y,'-');a.data_bounds = [0,0;cols,rows];

Two tricky things though:

1st: image coordinates (center of pixel) start at "1", hence there is a gap
of 0.5 between image borders and the axes

2nd: it might become tricky if you want to have negative values on the axis.

Probably there is a way to shift the image to other position within the
coordinate system?


So....not sure if this helps your purpose.

You could also switch "ON" / "OFF" the background image by access the
children of the figure, such as:

IMGPlot = a.Children(2); // children(2) is the background in this
caseIMGPlot.visible = 'off';


A complete other way would be to combine two images of same size.
Say...background image is img1.

your plot = img2.
Plot the graph and save the figure as a temporary image.

load img1
load temporary image

If size (img1) == size(img2)....You could use SIVP module to linear combine
two images:

img_gray = double(RGB2Gray(img));img2 = zeros(rows, cols) +
255;img2(rows/2,:) = 0;img3 = imlincomb( 0.5, img_gray, 0.4, img2)
// the values here define some kind of transparency.figure();
ShowImage(img3,'');



Best regards,
Philipp
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background over my
image.
It seems that the image is always above the plot no matter what order the
uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not work
either.
Any idea?
ShowImage(im,'J2');
b=newaxes();
b.filled = "off";
plot(a)
JÅ
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
Antoine Monmayrant
2016-02-09 07:01:02 UTC
Permalink
Post by Jan Åge Langeland
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background
over my image.
It seems that the image is always above the plot no matter what order
the uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work either.
Any idea?
ShowImage(im,'J2');
Well, ShowImage comes from an atom module and is not part of Scilab.
Saddly, none of the image processing toolboxes work on my machine.
I even filled some bug reports on forge, but it did not trigger any reaction from the developpers.

Thanks anyway for your proposition,

Antoine
Post by Jan Åge Langeland
b=newaxes(); b.filled = "off"; plot(a)

Post by a***@laas.fr
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant
2016-02-09 07:04:09 UTC
Permalink
Post by Philipp Mühlmann
Well, as I understand you want to plot a function over an background image.
In the case the image pixel number fits the X-Y range of your graph it's
rather simple.
Well, it is, unless IPD does not work on your system, which is my case!
None, absolutely none of the image processing toolboxes work on my machine.
And it's not only my machine, it's the case for most of the machines we have at work.
So I cannot rely on an image processing toolbox to achieve what I want and I have to rely on base functions.

Thanks anyway for you help,

Antoine
Post by Philipp Mühlmann
img = ReadImage(IPD_PATH + 'demos\teaset.png');
rows = size(img,'r');cols = size(img,'c');
img(rows,1,:) = (0); // changing left lower image corner for
checking purpose
// change all 3 colour
channels to get a black pixel
ShowColorImage(img,'');
a = gca();a.axes_visible = ["on","on","off"];x = linspace(1,600,600);y
= 1/2*(x);plot(x,y,'-');a.data_bounds = [0,0;cols,rows];
1st: image coordinates (center of pixel) start at "1", hence there is a gap
of 0.5 between image borders and the axes
2nd: it might become tricky if you want to have negative values on the axis.
Probably there is a way to shift the image to other position within the
coordinate system?
So....not sure if this helps your purpose.
You could also switch "ON" / "OFF" the background image by access the
IMGPlot = a.Children(2); // children(2) is the background in this
caseIMGPlot.visible = 'off';
A complete other way would be to combine two images of same size.
Say...background image is img1.
your plot = img2.
Plot the graph and save the figure as a temporary image.
load img1
load temporary image
If size (img1) == size(img2)....You could use SIVP module to linear combine
img_gray = double(RGB2Gray(img));img2 = zeros(rows, cols) +
255;img2(rows/2,:) = 0;img3 = imlincomb( 0.5, img_gray, 0.4, img2)
// the values here define some kind of transparency.figure();
ShowImage(img3,'');
Best regards,
Philipp
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background over my
image.
It seems that the image is always above the plot no matter what order the
uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not work
either.
Any idea?
ShowImage(im,'J2');
b=newaxes();
b.filled = "off";
plot(a)

_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
Philipp Mühlmann
2016-02-09 07:34:23 UTC
Permalink
Well, the base function behind "ShowImage" is "Matplot".

You can use a search engine of your choice to find ShowImage.sci.

"ShowColorImage" than is using "ShowImage" to create a colored Image.

Hope that helps,

Philipp
Post by a***@laas.fr
Post by Philipp Mühlmann
Well, as I understand you want to plot a function over an background
image.
Post by Philipp Mühlmann
In the case the image pixel number fits the X-Y range of your graph it's
rather simple.
Well, it is, unless IPD does not work on your system, which is my case!
None, absolutely none of the image processing toolboxes work on my machine.
And it's not only my machine, it's the case for most of the machines we have at work.
So I cannot rely on an image processing toolbox to achieve what I want and
I have to rely on base functions.
Thanks anyway for you help,
Antoine
Post by Philipp Mühlmann
img = ReadImage(IPD_PATH + 'demos\teaset.png');
rows = size(img,'r');cols = size(img,'c');
img(rows,1,:) = (0); // changing left lower image corner for
checking purpose
// change all 3 colour
channels to get a black pixel
ShowColorImage(img,'');
a = gca();a.axes_visible = ["on","on","off"];x = linspace(1,600,600);y
= 1/2*(x);plot(x,y,'-');a.data_bounds = [0,0;cols,rows];
1st: image coordinates (center of pixel) start at "1", hence there is a
gap
Post by Philipp Mühlmann
of 0.5 between image borders and the axes
2nd: it might become tricky if you want to have negative values on the
axis.
Post by Philipp Mühlmann
Probably there is a way to shift the image to other position within the
coordinate system?
So....not sure if this helps your purpose.
You could also switch "ON" / "OFF" the background image by access the
IMGPlot = a.Children(2); // children(2) is the background in this
caseIMGPlot.visible = 'off';
A complete other way would be to combine two images of same size.
Say...background image is img1.
your plot = img2.
Plot the graph and save the figure as a temporary image.
load img1
load temporary image
If size (img1) == size(img2)....You could use SIVP module to linear
combine
Post by Philipp Mühlmann
img_gray = double(RGB2Gray(img));img2 = zeros(rows, cols) +
255;img2(rows/2,:) = 0;img3 = imlincomb( 0.5, img_gray, 0.4, img2)
// the values here define some kind of transparency.figure();
ShowImage(img3,'');
Best regards,
Philipp
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background
over my
Post by Philipp Mühlmann
Post by a***@laas.fr
image.
It seems that the image is always above the plot no matter what order
the
Post by Philipp Mühlmann
Post by a***@laas.fr
uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work
Post by Philipp Mühlmann
Post by a***@laas.fr
either.
Any idea?
ShowImage(im,'J2');
b=newaxes();
b.filled = "off";
plot(a)
JÅ
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
Antoine Monmayrant
2016-02-09 08:09:50 UTC
Permalink
Post by Philipp Mühlmann
Well, the base function behind "ShowImage" is "Matplot".
I don't get what you mean.
My point is the following: "ShowImage" is not defined in the scilab base install.
You have to install an atom module to get access to it, in this case, it's IPD.
Saddly, IPD is broken for both the fedora and ubuntu linux distributions we use at work so I cannot use it.
IPD fails at detecting the installed opencv library installed.
I tried to patch "IPD.start" to load the installed opencv libs, but it crashes scilab.

Antoine
Post by Philipp Mühlmann
You can use a search engine of your choice to find ShowImage.sci.
"ShowColorImage" than is using "ShowImage" to create a colored Image.
Hope that helps,
Philipp
Post by a***@laas.fr
Post by Philipp Mühlmann
Well, as I understand you want to plot a function over an background
image.
Post by Philipp Mühlmann
In the case the image pixel number fits the X-Y range of your graph it's
rather simple.
Well, it is, unless IPD does not work on your system, which is my case!
None, absolutely none of the image processing toolboxes work on my machine.
And it's not only my machine, it's the case for most of the machines we
have at work.
So I cannot rely on an image processing toolbox to achieve what I want and
I have to rely on base functions.
Thanks anyway for you help,
Antoine
Post by Philipp Mühlmann
img = ReadImage(IPD_PATH + 'demos\teaset.png');
rows = size(img,'r');cols = size(img,'c');
img(rows,1,:) = (0); // changing left lower image corner for
checking purpose
// change all 3 colour
channels to get a black pixel
ShowColorImage(img,'');
a = gca();a.axes_visible = ["on","on","off"];x = linspace(1,600,600);y
= 1/2*(x);plot(x,y,'-');a.data_bounds = [0,0;cols,rows];
1st: image coordinates (center of pixel) start at "1", hence there is a
gap
Post by Philipp Mühlmann
of 0.5 between image borders and the axes
2nd: it might become tricky if you want to have negative values on the
axis.
Post by Philipp Mühlmann
Probably there is a way to shift the image to other position within the
coordinate system?
So....not sure if this helps your purpose.
You could also switch "ON" / "OFF" the background image by access the
IMGPlot = a.Children(2); // children(2) is the background in this
caseIMGPlot.visible = 'off';
A complete other way would be to combine two images of same size.
Say...background image is img1.
your plot = img2.
Plot the graph and save the figure as a temporary image.
load img1
load temporary image
If size (img1) == size(img2)....You could use SIVP module to linear
combine
Post by Philipp Mühlmann
img_gray = double(RGB2Gray(img));img2 = zeros(rows, cols) +
255;img2(rows/2,:) = 0;img3 = imlincomb( 0.5, img_gray, 0.4, img2)
// the values here define some kind of transparency.figure();
ShowImage(img3,'');
Best regards,
Philipp
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background
over my
Post by Philipp Mühlmann
Post by a***@laas.fr
image.
It seems that the image is always above the plot no matter what order
the
Post by Philipp Mühlmann
Post by a***@laas.fr
uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work
Post by Philipp Mühlmann
Post by a***@laas.fr
either.
Any idea?
ShowImage(im,'J2');
b=newaxes();
b.filled = "off";
plot(a)

_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
Jan Åge Langeland
2016-02-09 09:26:01 UTC
Permalink
Post by Antoine Monmayrant
Post by Philipp Mühlmann
Well, the base function behind "ShowImage" is "Matplot".
I don't get what you mean.
---
2nd: it might become tricky if you want to have negative values on the axis.
Probably there is a way to shift the image to other position within the
coordinate system?
If you look at the source code for ShowImage you should be able to
figure out how to plot an image with matplot(). However the tricky part
may be to get the image imported into Scilab without IPD. This is done
in c++ with ReadImageFile.cpp.
https://atoms.scilab.org/toolboxes/IPD/8.3.2/files/IPD-8.3.2-1-src.zip

If you manage to get an image into a graphical window, the purpose of
newaxes() is to make the XY range of the plot independent of the pixel
ranges.

Jan Å
Antoine Monmayrant
2016-02-09 12:36:06 UTC
Permalink
Post by Jan Åge Langeland
Post by Antoine Monmayrant
Post by Philipp Mühlmann
Well, the base function behind "ShowImage" is "Matplot".
I don't get what you mean.
---
2nd: it might become tricky if you want to have negative values on the axis.
Probably there is a way to shift the image to other position within the
coordinate system?
If you look at the source code for ShowImage you should be able to
figure out how to plot an image with matplot(). However the tricky part
may be to get the image imported into Scilab without IPD. This is done
in c++ with ReadImageFile.cpp.
https://atoms.scilab.org/toolboxes/IPD/8.3.2/files/IPD-8.3.2-1-src.zip
If you manage to get an image into a graphical window, the purpose of
newaxes() is to make the XY range of the plot independent of the pixel
ranges.
Ah, OK, I get your point now: if I can convert my image into scilab data, I can plot this data and overlap an axis ontop.
Of course, you are right.
I was trying to use the uicontrol "image" to avoid the hassle of conversion and directly use the image, well as an image!
You are right, I can convert my image into ppm, load my ppm image into scilab as rgb hypermatrix and use Matplot + overlapped plots to get a backgournd.

Thanks,

Antoine
Post by Jan Åge Langeland
Jan Å
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Philipp Mühlmann
2016-02-09 16:49:15 UTC
Permalink
Just a side question to Antoine:

What do you mean with uicontrol "image".

Do you speak about creating an uicontrol of type "image" and try to put an
image into that uicontrol?

I tried this a couple of times, but didn't manage how to do that.
Never worked.

But I always thought this is a bug from the uicontrol and not from IPD or
SIVP.

Best regards,
Philipp
Post by Antoine Monmayrant
Post by Jan Åge Langeland
Le Mardi 9 Février 2016 08:34 CET, Philipp MÌhlmann <
Post by Philipp Mühlmann
Well, the base function behind "ShowImage" is "Matplot".
I don't get what you mean.
---
2nd: it might become tricky if you want to have negative values on the
axis.
Post by Jan Åge Langeland
Probably there is a way to shift the image to other position within the
coordinate system?
If you look at the source code for ShowImage you should be able to
figure out how to plot an image with matplot(). However the tricky part
may be to get the image imported into Scilab without IPD. This is done
in c++ with ReadImageFile.cpp.
https://atoms.scilab.org/toolboxes/IPD/8.3.2/files/IPD-8.3.2-1-src.zip
If you manage to get an image into a graphical window, the purpose of
newaxes() is to make the XY range of the plot independent of the pixel
ranges.
Ah, OK, I get your point now: if I can convert my image into scilab data,
I can plot this data and overlap an axis ontop.
Of course, you are right.
I was trying to use the uicontrol "image" to avoid the hassle of
conversion and directly use the image, well as an image!
You are right, I can convert my image into ppm, load my ppm image into
scilab as rgb hypermatrix and use Matplot + overlapped plots to get a
backgournd.
Thanks,
Antoine
Post by Jan Åge Langeland
Jan Å
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
There we have the salad.
Samuel Gougeon
2016-02-09 19:27:09 UTC
Permalink
Hello,

Without images, this post should pass the moderation ;)[to the
moderator: did you decrease the max size of body recently? It was
formerly possible to post with images and body> 100kB]
Post by a***@laas.fr
Hi everyone,
I just failed at placing an image behind a plot.
- create a figure
- create an image uicontrol
- create an axis
- plot in the axis
- set axis.filled="off"
Apparently I was wrong.
I did not find a way to overlap a plot with transparent background
over my image.
It seems that the image is always above the plot no matter what order
the uicontrol/axes where created.
I also tried to put both of them inside the same frame, but I did not
work either.
You may use the z coordinate of your flat curves to manage overlays, as in:

clf
x = linspace(0,20,200);
plot(x,sin(x))
e = gce();
c = e.children;
// Example with a local image. The image is from
Loading Image...
//xstring(0,-1,"$\scalebox{1}{\includegraphics{atoms.png}}$")
// Example with a remote image under http:// (http*s*: not accepted)
xstring(0,-1,"$\scalebox{1}{\includegraphics{Loading Image...}}$")
c.data(:,3) = 0.1; // <<<==== HERE
c.thickness = 2;You may then tune the scalebox factor. Actually, like with an
uicontrol(style="image"), the imported image is inlaid and is not
resized accordingly with the embedding graphical figure. HTH Samuel Gougeon
Jan Åge Langeland
2016-02-09 21:54:32 UTC
Permalink
Post by Samuel Gougeon
clf
x = linspace(0,20,200);
plot(x,sin(x))
e = gce();
c = e.children;
// Example with a local image. The image is from
https://atoms.scilab.org/atoms.png
//xstring(0,-1,"$\scalebox{1}{\includegraphics{atoms.png}}$")
// Example with a remote image under http:// (http*s*: not accepted)
xstring(0,-1,"$\scalebox{1}{\includegraphics{http://www.cnrs.fr/fr/z-tools/newune/themes/CNRSTheme/images/logocnrs.png}}$")
c.data(:,3) = 0.1; // <<<==== HERE
c.thickness = 2;You may then tune the scalebox factor. Actually, like with an
uicontrol(style="image"), the imported image is inlaid and is not
resized accordingly with the embedding graphical figure. HTH Samuel Gougeon
Samuel

Thank you for sharing these very good methods. It opens a lot of new
possibilities.

The way I want to use images in figure I find it better to modify your
script with newaxis() before plotting. This makes the picture stay
while zooming for instance:

clf
xstring(0,0,"$\scalebox{.3}{\includegraphics{http://photos.marinetraffic.com/ais/showphoto.aspx?photoid=445734}}$");
g=get("current_figure"); g.figure_size=[345,575]; b=newaxes(); b.filled
= "off"; x = linspace(0,20,200);
plot(x,sin(x))

By the way it would have been interesting to see an example with
uicontrol(style="image") that you mention. I could never get that right.

Brgds
Jan Å
grivet
2016-02-23 11:21:14 UTC
Permalink
Hello,
I am beginning to use digital filters to treat some data. As my first
step, I try to run the examples in the help,how to design an elliptic
filter (using Scilab 5.5.1, Win7-64). This works . However, when I
select a Butterworth filter:
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);
I get this error message:

Singularité de la fonction log ou tan.
at line 6 of function dbphi called by :
[db_repf, phi_repf] = dbphi(repf);

What did I miss ?
No bugs have been reported for function dbphi, but three similar bugs
are listed for iir.
Any suggestion welcome.
JPGrivet
Serge Steer
2016-02-23 13:21:05 UTC
Permalink
Please can you give more details :
value of Order and Fcutoff/Fs/2
and what you are doing with hz (because iir does not call dbphi)
Serge
Post by Samuel Gougeon
Hello,
I am beginning to use digital filters to treat some data. As my first
step, I try to run the examples in the help,how to design an elliptic
filter (using Scilab 5.5.1, Win7-64). This works . However, when I
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);
Singularité de la fonction log ou tan.
[db_repf, phi_repf] = dbphi(repf);
What did I miss ?
No bugs have been reported for function dbphi, but three similar bugs
are listed for iir.
Any suggestion welcome.
JPGrivet
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
grivet
2016-02-23 13:41:19 UTC
Permalink
Post by Serge Steer
value of Order and Fcutoff/Fs/2
and what you are doing with hz (because iir does not call dbphi)
Serge
I am just running the example found in "how to design an elliptic
filter". Here is the code:

Order = 2; // The order of the filter
Fs = 1000; // The sampling frequency
Fcutoff = 40; // The cutoff frequency

// We design a low pass elliptic filter
hz = iir <iir.html>(Order,'lp','ellip',[Fcutoff/Fs/2 0],[0.1 0.1]);

// We compute the frequency response of the filter
[frq,repf]=repfreq <repfreq.html>(hz,0:0.001:0.5);
[db_repf, phi_repf] = dbphi <dbphi.html>(repf);

// And plot the bode like representation of the digital filter
subplot <subplot.html>(2,1,1);
plot2d <plot2d.html>(Fs*frq,db_repf);
xtitle <xtitle.html>('Obtained Frequency Response (Magnitude)');
subplot <subplot.html>(2,1,2);
plot2d <plot2d.html>(Fs*frq,phi_repf);
xtitle <xtitle.html>('Obtained Frequency Response (Phase in degree)');


with 'ellip' replaced by 'butt', and [Fcutoff/Fs/2 0] replaced
byFcutoff/Fs/2.

I am beginning to use digital filters to treat some data. As my first
step, I try to run the examples in the help,how to design an elliptic
filter (using Scilab 5.5.1, Win7-64). This works . However, when I
Post by Serge Steer
Post by grivet
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);
Singularité de la fonction log ou tan.
[db_repf, phi_repf] = dbphi(repf);
What did I miss ?
No bugs have been reported for function dbphi, but three similar bugs
are listed for iir.
Any suggestion welcome.
JPGrivet
Serge Steer
2016-02-23 14:34:08 UTC
Permalink
Your problem arises because one frequency value you ask for corresponds
exactly to a zero of hz.num
log(roots(hz.num))/(2*%pi)
so you want to compute the gain in dB of a zero value which is -inf

To avoid such problem you can let repfreq to do the frequency
discretization.

[frq,repf]=repfreq <repfreq.html>(hz)
or equivalently
[frq,repf]=repfreq <repfreq.html>(hz,0,0.5)

in this case the discretization uses varying frequency step
Serge
Post by grivet
Post by Serge Steer
value of Order and Fcutoff/Fs/2
and what you are doing with hz (because iir does not call dbphi)
Serge
I am just running the example found in "how to design an elliptic
Order = 2; // The order of the filter
Fs = 1000; // The sampling frequency
Fcutoff = 40; // The cutoff frequency
// We design a low pass elliptic filter
hz = iir <iir.html>(Order,'lp','ellip',[Fcutoff/Fs/2 0],[0.1 0.1]);
// We compute the frequency response of the filter
[frq,repf]=repfreq <repfreq.html>(hz,0:0.001:0.5);
[db_repf, phi_repf] = dbphi <dbphi.html>(repf);
// And plot the bode like representation of the digital filter
subplot <subplot.html>(2,1,1);
plot2d <plot2d.html>(Fs*frq,db_repf);
xtitle <xtitle.html>('Obtained Frequency Response (Magnitude)');
subplot <subplot.html>(2,1,2);
plot2d <plot2d.html>(Fs*frq,phi_repf);
xtitle <xtitle.html>('Obtained Frequency Response (Phase in degree)');
with 'ellip' replaced by 'butt', and [Fcutoff/Fs/2 0] replaced
byFcutoff/Fs/2.
I am beginning to use digital filters to treat some data. As my first
step, I try to run the examples in the help,how to design an elliptic
filter (using Scilab 5.5.1, Win7-64). This works . However, when I
Post by Serge Steer
Post by grivet
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);
Singularité de la fonction log ou tan.
[db_repf, phi_repf] = dbphi(repf);
What did I miss ?
No bugs have been reported for function dbphi, but three similar
bugs are listed for iir.
Any suggestion welcome.
JPGrivet
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
grivet
2016-02-24 10:30:45 UTC
Permalink
I appreciate your help; however, neither suggestion works: I still get
the same error message.
The similar line
[frq,repf]=repfreq(hz,0.01,0.49);
has no problem
Post by Serge Steer
Your problem arises because one frequency value you ask for
corresponds exactly to a zero of hz.num
log(roots(hz.num))/(2*%pi)
so you want to compute the gain in dB of a zero value which is -inf
To avoid such problem you can let repfreq to do the frequency
discretization.
[frq,repf]=repfreq <repfreq.html>(hz) or equivalently
[frq,repf]=repfreq <repfreq.html>(hz,0,0.5)
in this case the discretization uses varying frequency step
Serge
Post by Serge Steer
value of Order and Fcutoff/Fs/2
and what you are doing with hz (because iir does not call dbphi)
Serge
Serge Steer
2016-02-24 20:40:46 UTC
Permalink
Post by grivet
I appreciate your help; however, neither suggestion works: I still get
the same error message.
The similar line
[frq,repf]=repfreq(hz,0.01,0.49);
has no problem
please can you save the hz value using the Scilab save function and send
the file?
Serge
Post by grivet
Post by Serge Steer
Your problem arises because one frequency value you ask for
corresponds exactly to a zero of hz.num
log(roots(hz.num))/(2*%pi)
so you want to compute the gain in dB of a zero value which is -inf
To avoid such problem you can let repfreq to do the frequency
discretization.
[frq,repf]=repfreq <repfreq.html>(hz)
or equivalently
[frq,repf]=repfreq <repfreq.html>(hz,0,0.5)
in this case the discretization uses varying frequency step
Serge
Post by Serge Steer
value of Order and Fcutoff/Fs/2
and what you are doing with hz (because iir does not call dbphi)
Serge
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
grivet
2016-02-25 17:10:07 UTC
Permalink
Post by Serge Steer
Post by grivet
I appreciate your help; however, neither suggestion works: I still
get the same error message.
The similar line
[frq,repf]=repfreq(hz,0.01,0.49);
has no problem
please can you save the hz value using the Scilab save function and
send the file?
Serge
Voila le code:
//filtre Butterworth
Order = 2; // The order of the filter
Fs = 1000; // The sampling frequency
Fcutoff = 40; // The cutoff frequency

// We design a low pass Butterworth filter
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);

// We compute the frequency response of the filter
[frq,repf]=repfreq(hz,0,0.5);
[db_repf, phi_repf] = dbphi(repf);

// And plot the bode like representation of the digital filter
subplot(2,1,1);
plot2d(Fs*frq,db_repf);
xtitle('Obtained Frequency Response (Magnitude)');
subplot(2,1,2);
plot2d(Fs*frq,phi_repf);
xtitle('Obtained Frequency Response (Phase in degree)');

iir est sauvegardé dans "svgd_iir" joint (binaire).

Cordialement,
JP Grivet
Serge Steer
2016-02-26 09:03:10 UTC
Permalink
Post by grivet
Post by Serge Steer
Post by grivet
I appreciate your help; however, neither suggestion works: I still
get the same error message.
The similar line
[frq,repf]=repfreq(hz,0.01,0.49);
has no problem
You are right the problem is exactly for the frequency 0.5 besause
exp(2*%pi*%i*0.5) -> - 1. + 1.225D-16i
and hz.num has 2 zeros very near -1

I checked the hz value with Matlab, the results are the same. So it
seems that hz is ok. So it is probabily a probleme due to floating point
computations procucing a zero value instead of a very small one.

Serge
Post by grivet
Post by Serge Steer
please can you save the hz value using the Scilab save function and
send the file?
Serge
//filtre Butterworth
Order = 2; // The order of the filter
Fs = 1000; // The sampling frequency
Fcutoff = 40; // The cutoff frequency
// We design a low pass Butterworth filter
hz = iir(Order,'lp','butt',Fcutoff/Fs/2,[0.1 0.1]);
// We compute the frequency response of the filter
[frq,repf]=repfreq(hz,0,0.5);
[db_repf, phi_repf] = dbphi(repf);
// And plot the bode like representation of the digital filter
subplot(2,1,1);
plot2d(Fs*frq,db_repf);
xtitle('Obtained Frequency Response (Magnitude)');
subplot(2,1,2);
plot2d(Fs*frq,phi_repf);
xtitle('Obtained Frequency Response (Phase in degree)');
iir est sauvegardé dans "svgd_iir" joint (binaire).
Cordialement,
JP Grivet
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant
2016-02-10 08:19:26 UTC
Permalink
Post by Samuel Gougeon
Post by Samuel Gougeon
You may use the z coordinate of your flat curves to manage overlays,
clf
x = linspace(0,20,200);
plot(x,sin(x))
e = gce();
c = e.children;
// Example with a local image. The image is from
https://atoms.scilab.org/atoms.png
//xstring(0,-1,"$\scalebox{1}{\includegraphics{atoms.png}}$")
// Example with a remote image under http:// (http*s*: not accepted)
xstring(0,-1,"$\scalebox{1}{\includegraphics{http://www.cnrs.fr/fr/z-tools/newune/themes/CNRSTheme/images/logocnrs.png}}$")
c.data(:,3) = 0.1; // <<<==== HERE
c.thickness = 2;You may then tune the scalebox factor. Actually, like with an
uicontrol(style="image"), the imported image is inlaid and is not
resized accordingly with the embedding graphical figure. HTH Samuel
Gougeon
Samuel
Thank you for sharing these very good methods. It opens a lot of new
possibilities.
The way I want to use images in figure I find it better to modify your
script with newaxis() before plotting. This makes the picture stay
clf
xstring(0,0,"$\scalebox{.3}{\includegraphics{http://photos.marinetraffic.com/ais/showphoto.aspx?photoid=445734}}$");
g=get("current_figure"); g.figure_size=[345,575]; b=newaxes(); b.filled
= "off"; x = linspace(0,20,200);
plot(x,sin(x))
By the way it would have been interesting to see an example with
uicontrol(style="image") that you mention. I could never get that right.
Here we go:


//Image inside a figure with exactly the right size
f = gcf();
imageWidth = 181;
imageHeight = 144;
f.axes_size=[imageWidth,imageHeight];

//here image parent can be set to something else than the figure f (like a frame, ...)
h = uicontrol("Parent", f, ..
"Style", "image", ..
"Position", [0 0 imageWidth imageHeight], ..
"String", SCI + "/modules/demo_tools/images/logo_scilab.png");
Post by Samuel Gougeon
Brgds
Jan Å
Jan Åge Langeland
2016-02-10 09:52:13 UTC
Permalink
Post by Antoine Monmayrant
f = gcf();
imageWidth = 181;
imageHeight = 144;
f.axes_size=[imageWidth,imageHeight];
//here image parent can be set to something else than the figure f (like a frame, ...)
h = uicontrol("Parent", f, ..
"Style", "image", ..
"Position", [0 0 imageWidth imageHeight], ..
"String", SCI + "/modules/demo_tools/images/logo_scilab.png");
Thank you, that works fine, but I find that I have more control over the
image with:

im2=SCI + "/modules/demo_tools/images/logo_scilab.png";
xstring(0.4,0.4,"$\scalebox{.5}{\includegraphics{"+im2+"}}$");

Jan Å
Antoine Monmayrant
2016-02-10 12:37:44 UTC
Permalink
Post by Jan Åge Langeland
Post by Antoine Monmayrant
f = gcf();
imageWidth = 181;
imageHeight = 144;
f.axes_size=[imageWidth,imageHeight];
//here image parent can be set to something else than the figure f (like a frame, ...)
h = uicontrol("Parent", f, ..
"Style", "image", ..
"Position", [0 0 imageWidth imageHeight], ..
"String", SCI + "/modules/demo_tools/images/logo_scilab.png");
Thank you, that works fine, but I find that I have more control over
im2=SCI + "/modules/demo_tools/images/logo_scilab.png";
xstring(0.4,0.4,"$\scalebox{.5}{\includegraphics{"+im2+"}}$");
Yes, you are right, it's more convenient.
The only added bonus with the uicontrol is that you have access to a
callback function to react to the user's action.

Antoine
Post by Jan Åge Langeland
Jan Å
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Antoine Monmayrant LAAS - CNRS
7 avenue du Colonel Roche
BP 54200
31031 TOULOUSE Cedex 4
FRANCE

Tel:+33 5 61 33 64 59

email : ***@laas.fr
permanent email : ***@polytechnique.org

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Samuel Gougeon
2016-02-10 19:11:33 UTC
Permalink
Post by Antoine Monmayrant
..../...
Thank you, that works fine, but I find that I have more control over
im2=SCI + "/modules/demo_tools/images/logo_scilab.png";
xstring(0.4,0.4,"$\scalebox{.5}{\includegraphics{"+im2+"}}$");
Yes, you are right, it's more convenient.
The only added bonus with the uicontrol is that you have access to a
callback function to react to the user's action.
Not even: as for the text style (http://bugzilla.scilab.org/7111), the
callback is not implemented for the image style. After your example, add:
h.callback_type=0;
h.callback = "disp(""Hello"")"
// Then click on the image => "Hello" should be displayed in the console
for each click, but nothing is displayed.
// You may change the instructions => nothing is never done.

Samuel
Jan-Åge Langeland
2016-02-11 09:00:45 UTC
Permalink
Post by Samuel Gougeon
Post by Antoine Monmayrant
The only added bonus with the uicontrol is that you have access to a
callback function to react to the user's action.
Not even: as for the text style (http://bugzilla.scilab.org/7111), the
h.callback_type=0;
h.callback = "disp(""Hello"")"
// Then click on the image => "Hello" should be displayed in the
console for each click, but nothing is displayed.
// You may change the instructions => nothing is never done.
Samuel
What would a callback bring anyway, that you cannot do with xclick() ?

Jan Å
Antoine Monmayrant
2016-02-11 09:11:50 UTC
Permalink
Post by Jan-Åge Langeland
Post by Samuel Gougeon
Post by Antoine Monmayrant
The only added bonus with the uicontrol is that you have access to a
callback function to react to the user's action.
Not even: as for the text style (http://bugzilla.scilab.org/7111), the
h.callback_type=0;
h.callback = "disp(""Hello"")"
// Then click on the image => "Hello" should be displayed in the
console for each click, but nothing is displayed.
// You may change the instructions => nothing is never done.
Samuel
What would a callback bring anyway, that you cannot do with xclick() ?
Well, callbacks are the "official" way of interacting with the user.
It would allow you to create an intereface in a consistant way, using only callbacks.

Antoine
Post by Jan-Åge Langeland
Jan Å
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Jan-Åge Langeland
2016-02-11 11:01:12 UTC
Permalink
What would a callback bring anyway, that you cannot do with xclick() ?
Post by Antoine Monmayrant
Well, callbacks are the "official" way of interacting with the user.
It would allow you to create an intereface in a consistant way, using only callbacks.
Antoine
Well you can put the image on top of a button:

figure()
h=uicontrol()
h.callback = "disp(""Hello"")"
h.position = [20,40,200,160]
im2=SCI + "/modules/demo_tools/images/logo_scilab.png";
h.string="$\scalebox{1}{\includegraphics{"+im2+"}}$"

I would really like to get the cursor position in the callback, like I
do with xclick(), so clicking on different part of the image can work
like a menu (Samuel?):

Jan Å
Samuel Gougeon
2016-02-11 19:14:38 UTC
Permalink
.../...
I would really like to get the cursor position in the callback, like
I do with xclick(), so clicking on different part of the image can
Why not putting xclick() in the callback ? :) Have a try.
Jan Åge Langeland
2016-02-11 20:07:37 UTC
Permalink
Post by Samuel Gougeon
.../...
I would really like to get the cursor position in the callback, like
I do with xclick(), so clicking on different part of the image can
Why not putting xclick() in the callback ? :) Have a try.
I did try:

h.callback="disp(xclick())"; //disp can obviously be replaced with a suitable selection function.

I can get it to work in a two click mode: First click the button, then
click an image next to the button.

The problem with making one big button with the picture on top, is that
xclick() will not give the correct cursor position when on top of a
button. Just static values [-2. -1. -1.].

"cbmenu - String: callback associated to a menu if |xclick| returns due
to a click on a menu. In this case, |ibutton|, |xcoord|, |ycoord|, and
|iwin| take arbitrary values".

Jan Å
Loading...