imread, reshape and zeros function syntax problems
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Manu Chaudhary
il 16 Gen 2022
Commentato: Manu Chaudhary
il 16 Gen 2022
I am completely new to matlab. Studing some sample codes to learn matlab. I have some basic questions in the below code:
input_image_filename= './Images/Image_64x64.jpg'; % It is a 64x64 colored image
input_im_3D= imread(input_image_filename);
What is the return type of input_im_3D ? What I observe that it is storing some huge data in the variable input_im_3D?
n_pix= 12288;
x = double(reshape(input_im_3D, [n_pix 1]));
What I observe is that reshape function is putting data in the single column of a excel sheet till 12288.
I am really not able to understand the working of reshape function? Return type of reshape function ? What changes double put in the results? What does the syntax of [n_data 1] means ?
n_data= 16384 ;
x = [x; zeros(n_data - n_pix , 1)];
Please also explain me the syntax of zeros?
0 Commenti
Risposta accettata
Walter Roberson
il 16 Gen 2022
imread() returns the data type stored in the file. The most common data type stored in image files is uint8(), but there are other possibilities. For example,
basename = tempname();
fn1 = basename + "logical.png";
fn3 = basename + "uint16.png";
img1 = rand([48 64]) < 0.5;
img3 = randi([0 65535], [48 64 3], 'uint16');
imwrite(img1, fn1);
imwrite(img3, fn3);
back1 = imread(fn1);
back3 = imread(fn3);
whos back1 back3
isequal(img1, back1)
isequal(img3, back3)
True floating point images are possible, but writing one out takes more work for demonstration takes more work than I care to bother with at the moment.
7 Commenti
Walter Roberson
il 16 Gen 2022
Remember that you started with a 64 x 64 x 3 matrix (RGB image), and you shaped that as a column of data, and then you added 4096 zeros to the end of the column. Now you are reshaping that result to 64 x 64 x 4.
But 4096 = 64 x 64, so what you have effectively done is taken the original 64 x 64 x 3 array, and added another layer of zeros on in the third dimension, giving you a 64 x 64 x 4 result. The same result could have been achieved by
y_data = input_im_3D;
y_data(:,:,4) = 0; %add a 4th layer that is all 0
After that, selecting y_data(1:64, 1:64, 1:3) would be the same as y_data(:,:,1:3)... which would be the data with that layer of 0 removed, giving you back the original data.
It is not clear why any of this is being done.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Encryption / Cryptography in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!