imread, reshape and zeros function syntax problems

2 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jan 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
Name Size Bytes Class Attributes back1 48x64 3072 logical back3 48x64x3 18432 uint16
isequal(img1, back1)
ans = logical
isequal(img3, back3)
ans = logical
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.
Manu Chaudhary
Manu Chaudhary on 16 Jan 2022
Trying to test quantum image processing application. Image converted to Textfile data of 16384 length-> Normalized -> Given Input to quantum circuit simulator -> Result taken out -> Image regenerated using matlab. Testing the basic input output image functionality of matlab.
Thank you Walter for this great help.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!