Multiplying matrices of different classes

13 ビュー (過去 30 日間)
Brian
Brian 2014 年 11 月 5 日
コメント済み: Ian Syndergaard 2022 年 2 月 11 日
In my applied math course, we're learning wavelet compression techniques, and my partner and I have so far constructed two matrices. One matrix is the wavelet transform - a 256*256 orthogonal matrix, class = double The other matrix is constructed by the imread command and is a 256*256 matrix, class = uint8
naturally, when I multiply these two matrices together, I get an error code. "MTIMES is not fully supported for integer classes. At least one input must be scalar."
This is my first time using matlab and using the user community. There is not a lot of direction from the instructor, so maybe I could get help on creating code for the next part of the project. To compress the resulting matrix, we need to order the elements from highest to lowest, and find the number of terms that satisfy (L1^2 +L2^2 +...+Lk^2)/ (total energy of the system) greater than or equal to .99
This project is the hardest I've ever worked on, and I'm not a whiz at computer science. Hopefully, I receive sufficient help. Thanks in advance.

回答 (3 件)

James Tursa
James Tursa 2014 年 11 月 5 日
編集済み: James Tursa 2014 年 11 月 5 日
For the first part of your question, to do a matrix multiply:
a = your double matrix
b = your uint8 matrix
c = a * double(b);
If you really wanted to do an element-wise multiply, then you would use .* instead. E.g.,
a = your double matrix
b = your uint8 matrix
c = a .* double(b);
Regarding the "compressing" issue. It is not clear how you want this done. Could you be more specific with some equations for how the c matrix is related to your (L1^2 +L2^2 +...+Lk^2)/ (total energy of the system) expression?

Brian
Brian 2014 年 11 月 5 日
In calculating threshold, one chooses a value close to .99 to signify how many low values in the matrix we can turn into zeros. Then, we make a list of values, L, from highest to lowest. We square these values so that we can compare it to the total energy of the system. The c matrix is a wavelet matrix times an image matrix, and its energy should be same as the original image.
  2 件のコメント
James Tursa
James Tursa 2014 年 11 月 5 日
I still don't get the connection. Is L1 = c(1,1), or is L1 = largest value in c matrix, or what? How specifically is the c matrix (the result of the matrix multiply) related to L1, L2, etc?
Brian
Brian 2014 年 11 月 5 日
L1 is the largest value in c. the c matrix is related to L1^2, L2^2 because the energy of the system is the sum of squares of all entries in the matrix. By finding the number of L values that satisfy the threshold, we are allowing the computer to use less storage

サインインしてコメントする。


Brian
Brian 2014 年 11 月 5 日
I am encountering a new problem: When I input an image using imread, the resulting matrix is 3-Dimensional. That is, 256x256x3 specifically. I can't multiply that with my wavelet matrix(256x256), and I need help.
  1 件のコメント
Ian Syndergaard
Ian Syndergaard 2022 年 2 月 11 日
I realize that I'm way late to answer this, but perhaps someone else will find this helpfull:
Your 256x256 image has a red layer, a green layer, and a blue layer. These three "layers" are stored in that 3rd dimension of your matrix.
There are two options:
1. You could compress each color layer individually by extracting the different color layers as follows:
photo_data = imread("photo_file.jpg");
red_layer = photo_data(:,:,1);
green_layer = photo_data(:,:,2);
blue_layer = photo_data(:,:,3);
2. You could create a greyscale image by simply using one of the three colors or by averaging the three colors as follows:
photo_data = imread("photo_file.jpg");
greyscale_data = uint8(mean(photo_data));

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContinuous Wavelet Transforms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by