Reputation: 2472
f=imread('cameraman.tif');
f=im2bw(f);
[m,n]=size(f);
s1=zeros(m,2*n);
s1(1:end,1:2:end)=f(1:end,1:end);
Here is what i think the code does. We are changing s1, by comparing and replacing its element with the elements of f. s1 is a 256x512 double matrix where as f is a 256x256 logical matrix. But i don't think that's correct because after seeing and matching both the matrix i saw that not all the elements were in that fashion.
Can please someone briefly explain what does this code actually do? And how actually it done? Thanks in advance.
Upvotes: 1
Views: 102
Reputation: 2508
The code has been explained well by other answer, so how about an example to give you a graphical illustration.
First, you should know by im2bw
, the image is turned into black and white, meaning the image matrix is converted to 2D.
Input image:
Black and White image:
Output image:
Note that the third image has been augmented with zeros in even-columns. DOUBLE FAT!
Zoom in at left upper corner:
Upvotes: 2
Reputation: 539
f=imread('cameraman.tif');
loading file to f
f=im2bw(f);
converting f to black and white f
[m,n]=size(f);
getting size od array (simple: image dimensions)
s1=zeros(m,2*n);
creating an array of zeros - dimension of new array is double (you can insert 2 cameraman.tif images inside s1 left and right because this is 2* columns )
s1(1:end,1:2:end)=f(1:end,1:end);
this line is a little tricky - it inserts image f into image s1 but every second line so it looks widen you can see it yourself :) just
imshow(s1);
Upvotes: 0
Reputation: 47392
These lines read an image from a file and convert it to a binary image (so that f
is now a logical matrix.)
f=imread('cameraman.tif');
f=im2bw(f);
These lines create a new matrix s1
which has the same number of rows as f
but twice the number of columns.
[m,n]=size(f);
s1=zeros(m,2*n);
This line fills every other column of s1
with the values of f
. The result is that the odd-numbered columns (1,3,5....) in s
will contain a copy of f
and the even-numbered columns (2,4,6...) will be zero.
s1(1:end,1:2:end)=f(1:end,1:end);
Note that it's actually being a little verbose; you could get the same result by doing
s1(:,1:2:end) = f;
Upvotes: 4