Question

I want to compute the morlet wavelet of each row of 480X480 image. I have to save the output of the transform of each row which is a 2d array(matrix).

Then i will be taking the average all 480 2d matrices i have to get one final plot of the average.

clc;
close all;
clear all;
I=imread('lena.jpg');
J=rgb2gray(I);
%K=J(1:480)
%coefs = cwt(K,1:128,'morl','plot');


coefs = cell(480,1);
for i = 1:480
   K=J(i,:);
coefs(i) = cwt(K,1:128,'morl');
end  

Here i want to take the avg of the 480 coeff matrices. Here am getting the error

Conversion to cell from double is not possible.

Error in soilwave (line 12) coefs(i) = cwt(K,1:128,'morl');

Could anyone suggest a better method or tweaks to this.

Was it helpful?

Solution

Cell arrays are practical if you need to store elements that have inconsistent format or dimensions, but for what you are trying to do, a 3D array is easier to work with. Here is what I would do:

Preassign a 3D array:

coefs = zeros(128, size(J, 2), size(J,1));

then compute and populate the stack:

for ii = 1:size(J, 1)
   K=J(ii,:);
   coefs(:,:,ii) = cwt(K,1:128,'morl');
end  

Finally, compute the mean along the third dimension:

MeanCoeff=mean(coefs, 3);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top