# LoadError: DimensionMismatch

**URL:** <https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507>\
**Category:** General Usage\
**Created:** [March 4, 2020, 8:39am UTC](https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507 "2020-03-04T08:39:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eldho.Ashna](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Eldho.Ashna](https://discourse.julialang.org/u/Eldho.Ashna)\
**Post date:** [March 4, 2020, 8:39am UTC](https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507/1 "2020-03-04T08:39:46Z")

</div>

Hi everyone,

I was trying to rewrite the following python code:

```julia
import numpy as np
import cv2 
import matplotlib.pyplot as plt

img = cv2.imread('/home/julia_Hands_on/cat3.jpg')
img_tinted = img * [1, 0.95, 0.9]
print(img_tinted)
# Show the original image
plt.subplot(1, 2, 1)
plt.imshow(img)

# Show the tinted image
plt.subplot(1, 2, 2)
plt.imshow(np.uint8(img_tinted))
plt.show()

```

In julia, I wrote it as:

```julia
using Images, ImageView, Plots
img=load("/home/julia_Hands_on/cat3.jpg")
img_tinted = img * [1, 0.95, 0.9]
#gr()

```

but, it gives the following error:

```julia
ERROR: LoadError: DimensionMismatch("matrix A has dimensions (214,393), vector B has length 3")
Stacktrace:
 [1] generic_matvecmul!(::Array{RGB{Float64},1}, ::Char, ::Array{RGB{Normed{UInt8,8}},2}, ::Array{Float64,1}, ::LinearAlgebra.MulAddMul{true,true,Bool,Bool}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/matmul.jl:609
 [2] mul! at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/matmul.jl:81 [inlined]
 [3] mul! at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/matmul.jl:203 [inlined]
 [4] *(::Array{RGB{Normed{UInt8,8}},2}, ::Array{Float64,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/matmul.jl:51
 [5] top-level scope at /home/g2-test/julia_Hands_on/python_julia/numpy_conversion.jl:56
 [6] include at ./boot.jl:328 [inlined]
 [7] include_relative(::Module, ::String) at ./loading.jl:1105
 [8] include(::Module, ::String) at ./Base.jl:31
 [9] include(::String) at ./client.jl:424
 [10] top-level scope at REPL[1]:1
in expression starting at /home/g2-test/julia_Hands_on/python_julia/numpy_conversion.jl:3

```

The python code ran without any errors. Why is it showing error for julia? Can someone help me.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 4, 2020, 8:43am UTC](https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507/2 "2020-03-04T08:43:30Z")

</div>

I assume the 3 values are RGB channels? but how do you expect a `214x393` matrix to multiply with a `1x3` vector?

---

<div class="post-metadata">

**Author:** ![Eldho.Ashna](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Eldho.Ashna](https://discourse.julialang.org/u/Eldho.Ashna)\
**Post date:** [March 4, 2020, 8:46am UTC](https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507/3 "2020-03-04T08:46:23Z")

</div>

> [@jling](#):
>
> I assume the 3 values are RGB channels?

No, it is [1, 0.95, 0.9].

Then, why python is running and giving output?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 4, 2020, 8:53am UTC](https://discourse.julialang.org/t/loaderror-dimensionmismatch/35507/4 "2020-03-04T08:53:04Z")

</div>

well I know it is `[1, 0.95, 0.9]`, but do they represent scaling on RBG channel? otherwise I don’t understand why you would multiply image pixels by 3 random number.

> [@Eldho.Ashna](#):
>
> why python is running and giving output

because `img` in python is probably **not** just a 2D matrix? Again, no language would know how to multiply a `214x393` matrix by a `1x3` vector out-of-box.

* * *

now, if your `1x3` vector represents scaling of different `RGB` channel, then you want to try using this

```julia
julia> img = testimage("mandrill")
julia> size(img)
(512, 512)

julia> size(img |> channelview)
(3, 512, 512)

julia> img_tinted = channelview(img) .* [1, 0.95, 0.9]

```

[https://juliaimages.org/latest/function\_reference/#ImageCore.channelview](https://juliaimages.org/latest/function_reference/#ImageCore.channelview)
