How to convert sparse matrix into image?

15 ビュー (過去 30 日間)
bavani marimuthu
bavani marimuthu 2017 年 12 月 21 日
回答済み: Meet 2024 年 7 月 31 日
I have a sparse matrix which contains aa = (1,1) 72 (1,2) 101 (1,3) 108
Now I want to convert this into image ...?

回答 (1 件)

Meet
Meet 2024 年 7 月 31 日
Hi Bavani,
Assuming you already have the sparse matrix, to convert it to an image, you first need to convert the sparse matrix to a full matrix using the "full" function. This function will return a full matrix where the empty cell entries from the sparse matrix are filled with zeros.
If the values in the sparse matrix are in the range [0, 255] and the datatype of the matrix is "double", you need to convert it to "uint8", as "uint8" supports values in the range [0, 255]. You can then pass this "uint8" matrix to the "imshow" function to display the image.
Example code to generate an image from sparse matrix:
row = [1, 1, 1];
col = [1, 2, 3];
val = [72, 101, 108];
sparseMatrix = sparse(row, col, val);
fullMatrix = full(sparseMatrix);
output_matrix = uint8(fullMatrix);
imshow(output_matrix);
For more information, you can refer to the following documentation links:

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by