[Scilab-users] convert matlab code to scilab

classic Classic list List threaded Threaded
8 messages Options
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] convert matlab code to scilab

Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

Hello

Le 16/10/2019 à 11:46, P M a écrit :
Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?

by dummy names, e.g.

[ans,ans,Minstances_hat] = unique(B(:));

There is no equivalent mechanism in Scilab.
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

[ans,ans,Minstances_hat] = unique(B(:));
gives:  Wrong number of output arguments.

I also tried :
[Minstances_hat] = unique(B(:));
and get a vector.
also
[Minstances_hat,index] = unique(B(:));
seem to work.


However afterwards there is this line:
masks = reshape(Minstances_hat-1,size(B));
I try to convert via:
mask = matrix(Minstances_hat-1,size(B));
but no success.






Am Mi., 16. Okt. 2019 um 11:50 Uhr schrieb Stéphane Mottelet <[hidden email]>:

Hello

Le 16/10/2019 à 11:46, P M a écrit :
Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?

by dummy names, e.g.

[ans,ans,Minstances_hat] = unique(B(:));

There is no equivalent mechanism in Scilab.
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

Sorry, I thought you were just asking about the tildas, not the syntax of unique() in Scilab.

Please see

https://help.scilab.org/docs/6.0.2/en_US/unique.html

vs

https://fr.mathworks.com/help/matlab/ref/unique.html

Matlab syntax [C,ia,ic] = unique(___)  with 3 outputs has no equivalent in Scilab. i.e. in Matlab, after  [C,ia,ic] = unique(A) then A=C(ic), i.e. values in ic are the indices of corresponding unique value in C.  They can be recovered with the quick and dirty following loop:

for i=1:length(a)
     ia(i)=find(a(i)==C)
end

S.

Le 16/10/2019 à 12:10, P M a écrit :
[ans,ans,Minstances_hat] = unique(B(:));
gives:  Wrong number of output arguments.

I also tried :
[Minstances_hat] = unique(B(:));
and get a vector.
also
[Minstances_hat,index] = unique(B(:));
seem to work.


However afterwards there is this line:
masks = reshape(Minstances_hat-1,size(B));
I try to convert via:
mask = matrix(Minstances_hat-1,size(B));
but no success.






Am Mi., 16. Okt. 2019 um 11:50 Uhr schrieb Stéphane Mottelet <[hidden email]>:

Hello

Le 16/10/2019 à 11:46, P M a écrit :
Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?

by dummy names, e.g.

[ans,ans,Minstances_hat] = unique(B(:));

There is no equivalent mechanism in Scilab.
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

Sorry, in my answer the loop constructs "ic", not  "ia", i.e. the full equivalent to Matlab's "[C,ia,ic] = unique(A)" is in Scilab:

[C,ia] = unique(A)
for i=1:length(A)
    ic(i)=find(A(i)==C)
end

S.

Le 16/10/2019 à 13:19, Stéphane Mottelet a écrit :

Sorry, I thought you were just asking about the tildas, not the syntax of unique() in Scilab.

Please see

https://help.scilab.org/docs/6.0.2/en_US/unique.html

vs

https://fr.mathworks.com/help/matlab/ref/unique.html

Matlab syntax [C,ia,ic] = unique(___)  with 3 outputs has no equivalent in Scilab. i.e. in Matlab, after  [C,ia,ic] = unique(A) then A=C(ic), i.e. values in ic are the indices of corresponding unique value in C.  They can be recovered with the quick and dirty following loop:

for i=1:length(a)
     ia(i)=find(a(i)==C)
end

S.

Le 16/10/2019 à 12:10, P M a écrit :
[ans,ans,Minstances_hat] = unique(B(:));
gives:  Wrong number of output arguments.

I also tried :
[Minstances_hat] = unique(B(:));
and get a vector.
also
[Minstances_hat,index] = unique(B(:));
seem to work.


However afterwards there is this line:
masks = reshape(Minstances_hat-1,size(B));
I try to convert via:
mask = matrix(Minstances_hat-1,size(B));
but no success.






Am Mi., 16. Okt. 2019 um 11:50 Uhr schrieb Stéphane Mottelet <[hidden email]>:

Hello

Le 16/10/2019 à 11:46, P M a écrit :
Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?

by dummy names, e.g.

[ans,ans,Minstances_hat] = unique(B(:));

There is no equivalent mechanism in Scilab.
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

Dear Stephane,

thanks for your help.
I think in my case the problem is solved just by using:
[Minstances_hat] = unique(B(:));
This gives a vector of used px-values for different objects shown in image.
Each object is defined by a single pixel value.
Since B is the B-plane of an RGB-image, it is possible to assign each pixel from the original image to an object using these values.

Thanks again,
Philipp


Am Mi., 16. Okt. 2019 um 13:27 Uhr schrieb Stéphane Mottelet <[hidden email]>:

Sorry, in my answer the loop constructs "ic", not  "ia", i.e. the full equivalent to Matlab's "[C,ia,ic] = unique(A)" is in Scilab:

[C,ia] = unique(A)
for i=1:length(A)
    ic(i)=find(A(i)==C)
end

S.

Le 16/10/2019 à 13:19, Stéphane Mottelet a écrit :

Sorry, I thought you were just asking about the tildas, not the syntax of unique() in Scilab.

Please see

https://help.scilab.org/docs/6.0.2/en_US/unique.html

vs

https://fr.mathworks.com/help/matlab/ref/unique.html

Matlab syntax [C,ia,ic] = unique(___)  with 3 outputs has no equivalent in Scilab. i.e. in Matlab, after  [C,ia,ic] = unique(A) then A=C(ic), i.e. values in ic are the indices of corresponding unique value in C.  They can be recovered with the quick and dirty following loop:

for i=1:length(a)
     ia(i)=find(a(i)==C)
end

S.

Le 16/10/2019 à 12:10, P M a écrit :
[ans,ans,Minstances_hat] = unique(B(:));
gives:  Wrong number of output arguments.

I also tried :
[Minstances_hat] = unique(B(:));
and get a vector.
also
[Minstances_hat,index] = unique(B(:));
seem to work.


However afterwards there is this line:
masks = reshape(Minstances_hat-1,size(B));
I try to convert via:
mask = matrix(Minstances_hat-1,size(B));
but no success.






Am Mi., 16. Okt. 2019 um 11:50 Uhr schrieb Stéphane Mottelet <[hidden email]>:

Hello

Le 16/10/2019 à 11:46, P M a écrit :
Dear experts,

trying to convert a matlab code to scilab I come across following line:
[~,~,Minstances_hat] = unique(B(:));
How to replace the "~" symbol?

by dummy names, e.g.

[ans,ans,Minstances_hat] = unique(B(:));

There is no equivalent mechanism in Scilab.
B is the blue channel of a RGB image...hence a m x n matrix of integers (type(B) = 8 )

Thank you,
Philipp

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

In reply to this post by mottelet
Le 16/10/2019 à 13:27, Stéphane Mottelet a écrit :
>
> Sorry, in my answer the loop constructs "ic", not  "ia", i.e. the full
> equivalent to Matlab's "[C,ia,ic] = unique(A)" is in Scilab:
>
> [C,ia] = unique(A)
> for i=1:length(A)
>     ic(i)=find(A(i)==C)
> end
>

ic = ones(A);
for i = 1:length(ia)
     ic(A==C(i)) = i;
end
// Check:
and(A==C(ic))

will be always (much) shorter and faster (in case of high redundancy).

Samuel

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: convert matlab code to scilab

In reply to this post by mottelet
Le 16/10/2019 à 13:19, Stéphane Mottelet a écrit :

Sorry, I thought you were just asking about the tildas, not the syntax of unique() in Scilab.

Please see

https://help.scilab.org/docs/6.0.2/en_US/unique.html

vs

https://fr.mathworks.com/help/matlab/ref/unique.html

Matlab syntax [C,ia,ic] = unique(___)  with 3 outputs has no equivalent in Scilab.


If this output option is required, this request should be urgently reported on Bugzilla.
Indeed, some new unique() features have been implemented and pushed on the Scilab forge for Scilab 6.1.0,
and are pending, in answer to
http://bugzilla.scilab.org/8418 http://bugzilla.scilab.org/15522 http://bugzilla.scilab.org/15795
Such a request would challenge the third output position.
To me, the third foreseen output -- that is the vector of numbers of occurrences -- would be more useful, and faster to compute, so rather to appear before possibly ic in the output list.

Please note that ic should be computed as well in case of "r" or "c" option.

Regards
Samuel


i.e. in Matlab, after  [C,ia,ic] = unique(A) then A=C(ic), i.e. values in ic are the indices of corresponding unique value in C.  They can be recovered with the quick and dirty following loop:

for i=1:length(a)
     ia(i)=find(a(i)==C)
end

S.


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users