[Scilab-users] Element Wise multipliication in Scilab

sgougeon at free.fr sgougeon at free.fr
Thu Jun 8 14:19:55 CEST 2017


Hello,

>----- Mail original -----
>
> During Image Processing, I have an extracted small matrix 
>
> Mat = 
>
>  152  149  151  
>  159  151  147  
>  158  152  152  
>
> and a simple flipped sobel mask 
>
> Gy  =
> 
>  - 1.  - 2.  - 1.  
>    0.    0.    0.  
>    1.    2.    1.  
>
> To calculate the gradient in y-direction, I multiply elementwise (and would
> sum later if the values were right)
>
> Gy.*Mat, which funnily gives
>
>  104  214  105  
>    0    0    0  
>  158   48  152  
>
> Why aren't the first row values negative (They even appear morphed somehow).
>

Because 
a) numbers in Mat are encoded as unsigned integers (they are displayed without decimal dot),
+
b)in Scilab, integers win over floats.
+
c) in Scilab, overflowing integers are wrapped, not ceiled nor floored.

You will get want you likely expect with 
Gy .* double(Mat)

>Scilab help shows that .* may calculate the kronecker product of the two
>matrices. 

Could you give us a pointer where this is written?
The kronecker operator is .*.

>How do I calculate the real element wise multiplication?

With .*, after casting Mat to decimal encoding.

HTH
Samuel Gougeon



More information about the users mailing list