matlab - Is it possible to multiply a 3x3 matrix (a color transformation) with a rank 3 tensor/3D matrix (a color image)? -
when images read in, converted matrices/tensors of dimension (x,y,3) last 1 r, g, b channels.
i looking apply colorspace conversion, that's 3x3 matrix want apply each pixel. i'm sort of looking here "component wise" matrix-vector multiply.
can done matlab/octave? i'm using octave seems if there's way matlab should have fighting chance octave.
i'm getting this:
octave:15> b b = 0.9465229 0.2946927 -0.1313419 -0.1179179 0.9929960 0.0073716 0.0923046 -0.0464579 0.9946464 octave:16> b * y error: invalid conversion of ndarray matrix i guess gotta nested loop manually. when try this:
blena = lena; %// copy structure -- here lena rgb image of type double i=1:rows(lena) j=1:columns(lena) blena(i,j) = b * lena(i,j,:); endfor endfor lena(i,j,:) still ndarray.
sure. need reshapeing:
im = rand(100,150,3); %// example "image" t = rand(3,3); %// example transform matrix result = reshape((t * reshape(im, [], 3).').', size(im)); this arranges original image 3-row matrix (each row color component, each column pixel), matrix multiplication, , puts shape.
Comments
Post a Comment