From: Nehal on
I have 1500 binary images. I have been trying to create a matrix that will have 1500 number of columns. Each column will contain all the image elements of an image.

Here's the code I have been trying:


function test

tifFiles = dir('*.tif'); %takes all the images from the folder Sample

for k = 1:length(tifFiles) %the loop will continue for the number of images

filename = tifFiles(k).name; % takes the an image and it's file name

I = imread(filename); % reads the image to I

F(k) = reshape(I,[],1); % reshapes the matrix into 1 column

end

G = [F(1):F(k)]; % creates the final matrix

end


but it's showing error:
??? Subscripted assignment dimension mismatch.
Error in ==> test at 9
F(k) = reshape(I,[],1);


What's wrong..? can anyone plz help me..?
From: Walter Roberson on
Nehal wrote:
> I have 1500 binary images. I have been trying to create a matrix that
> will have 1500 number of columns. Each column will contain all the image
> elements of an image.

You do not, however, promise that all of the images are exactly the same size.


> Here's the code I have been trying:
>
>
> function test
>
> tifFiles = dir('*.tif'); %takes all the images from the folder Sample
>
> for k = 1:length(tifFiles) %the loop will continue for the number of
> images
> filename = tifFiles(k).name; % takes the an image and it's
> file name
> I = imread(filename); % reads the image to I
>
> F(k) = reshape(I,[],1); % reshapes the matrix into 1 column

F(k) is a single location, and you are trying to store an entire column in
that location. *If* you are sure that each image is exactly the same size,
instead use F(:,k) as the destination.

> end
>
> G = [F(1):F(k)]; % creates the final matrix

and in that case you would not use G

>
> end
>
>
> but it's showing error:
> ??? Subscripted assignment dimension mismatch.
> Error in ==> test at 9
> F(k) = reshape(I,[],1);
>
>
> What's wrong..? can anyone plz help me..?


If the matrices are not necessarily all exactly the same file, then use cell
arrays, F{k} = reshape... However in that case you would have to figure out
what it means to put everything into the same matrix.
From: Matt J on
"Nehal " <arnab620(a)yahoo.com> wrote in message <i3hoas$6f$1(a)fred.mathworks.com>...

> but it's showing error:
> ??? Subscripted assignment dimension mismatch.
> Error in ==> test at 9
> F(k) = reshape(I,[],1);
======

F(k) is a 1x1 location in an array and you're trying to shove a non-scalar quantity into it.
The line G = [F(1):F(k)] is also not what you want.

Probably the best thing to do, assuming you've pre-allocated G (recommended) is the following:

function test

tifFiles = dir('*.tif'); %takes all the images from the folder Sample

for k = 1:length(tifFiles) %the loop will continue for the number of images

filename = tifFiles(k).name; % takes the an image and it's file name

I = imread(filename); % reads the image to I

G(:,k)= I(:); % reshapes the matrix into 1 column

end



end
From: us on
"Nehal " <arnab620(a)yahoo.com> wrote in message <i3hoas$6f$1(a)fred.mathworks.com>...
> I have 1500 binary images. I have been trying to create a matrix that will have 1500 number of columns. Each column will contain all the image elements of an image.
>
> Here's the code I have been trying:
>
>
> function test
>
> tifFiles = dir('*.tif'); %takes all the images from the folder Sample
>
> for k = 1:length(tifFiles) %the loop will continue for the number of images
>
> filename = tifFiles(k).name; % takes the an image and it's file name
>
> I = imread(filename); % reads the image to I
>
> F(k) = reshape(I,[],1); % reshapes the matrix into 1 column
>
> end
>
> G = [F(1):F(k)]; % creates the final matrix
>
> end
>
>
> but it's showing error:
> ??? Subscripted assignment dimension mismatch.
> Error in ==> test at 9
> F(k) = reshape(I,[],1);
>
>
> What's wrong..? can anyone plz help me..?

one of the solutions

flst=dir('*.tif');
nf=numel(flst);
dat=cell(flst,1);
for i=1:nf
img=imread(flst(i).name);
dat{i,1}=img(:);
end
dat=cat(2,dat{:});

us
From: Nehal on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i3hotk$7k9$1(a)fred.mathworks.com>...
> "Nehal " <arnab620(a)yahoo.com> wrote in message <i3hoas$6f$1(a)fred.mathworks.com>...
>
> > but it's showing error:
> > ??? Subscripted assignment dimension mismatch.
> > Error in ==> test at 9
> > F(k) = reshape(I,[],1);
> ======
>
> F(k) is a 1x1 location in an array and you're trying to shove a non-scalar quantity into it.
> The line G = [F(1):F(k)] is also not what you want.
>
> Probably the best thing to do, assuming you've pre-allocated G (recommended) is the following:
>
> function test
>
> tifFiles = dir('*.tif'); %takes all the images from the folder Sample
>
> for k = 1:length(tifFiles) %the loop will continue for the number of images
>
> filename = tifFiles(k).name; % takes the an image and it's file name
>
> I = imread(filename); % reads the image to I
>
> G(:,k)= I(:); % reshapes the matrix into 1 column
>
> end
>
>
>
> end


actually I was trying....

G = [image1 image2 image3 ..... image1500]

where
image1 = [ 1st element of 1st image
2nd element of 1st image
3rd element of 1st image
.
.
last element of 1st image ]

image1 has only 1 column and G has 1500 columns.