Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
frames stored to array

Subject: frames stored to array

From: Vaishali

Date: 22 Sep, 2012 11:34:09

Message: 1 of 10

I have converted my video into frames and stored it in a folder. Now i have to read those frames into an array and compare them. I am not able to store it in an array. I get error such as subscript mismatch. Can anyone please help me??

Subject: frames stored to array

From: Sadik

Date: 22 Sep, 2012 12:16:08

Message: 2 of 10

H?i Vaishali,

If I were you, I would first read them in a for loop individually and check that they are in deed of the same size. Another thing to check is the size of the array you are using to store the frames. All in all, using the size function in both cases, you can easily pinpoint the problem.

Best.

Subject: frames stored to array

From: Vaishali

Date: 22 Sep, 2012 12:36:09

Message: 3 of 10

can u please help me with the code. I am actually kind a new to matlab

Subject: frames stored to array

From: dpb

Date: 22 Sep, 2012 12:40:59

Message: 4 of 10

On 9/22/2012 7:36 AM, Vaishali wrote:
> can u please help me with the code. I am actually kind a new to matlab

Show what you've done to date...

doc debug

--

Subject: frames stored to array

From: Vaishali

Date: 22 Sep, 2012 13:30:10

Message: 5 of 10

 i have converted video to frames. next i hv to compare which two images hv the high difference rates

Subject: frames stored to array

From: Vaishali

Date: 22 Sep, 2012 13:34:08

Message: 6 of 10

i have converted video to frames. next nw i hv to find whch two images have the high dofference.. I have sent my code to ur mail

Subject: frames stored to array

From: dpb

Date: 22 Sep, 2012 13:36:27

Message: 7 of 10

On 9/22/2012 8:30 AM, Vaishali wrote:
> i have converted video to frames....

And where is the code which prompted the thread?

How do you expect somebody to tell anything whatsoever about what you
might have done wrong w/o seeing what it is you actually did?

The point of cs-sm is _not_ for somebody else to write code for you but
to hopefully provide assistance to specific problems...you said you had
a problem but haven't provided any info as to which would let anybody
diagnose the cause.

Nor have you indicated you've made any real attempt to use the debugging
tools available to you to try to resolve it on your own...

doc size

--

Subject: frames stored to array

From: dpb

Date: 22 Sep, 2012 14:39:19

Message: 8 of 10

On 9/22/2012 8:34 AM, Vaishali wrote:
...

> ... I have sent my code to ur mail

Ain't gonna' get here and wouldn't respond if did..."What starts in
usenet stays in usenet..."

Post here the pertinent (short) snippets where you're having a problem
w/ the specific error messages and results of your debugging session
showing results of size() etc., on the offending arrays in the line in
question (of course, when you do that, you'll probably have uncovered
the source of the problem and can solve it yourself).

--

Subject: frames stored to array

From: Vaishali

Date: 22 Sep, 2012 15:01:09

Message: 9 of 10

myFolder = 'C:\Users\user\Documents\MATLAB\traffic';
filePattern = fullfile(myFolder, '*.jepg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
  baseFileName = jpegFiles(k).name;
  fullFileName = fullfile(myFolder, baseFileName);
  fprintf(1, 'Now reading %s\n', fullFileName);
  imageArray = imread(fullFileName);
  imshow(imageArray); % Display image.
  drawnow; % Force display to update immediately.
end

Subject: frames stored to array

From: Sadik

Date: 22 Sep, 2012 15:31:09

Message: 10 of 10

Hi Vaishali,

Let me fix one typo: '*.jpeg' rather than '*.jepg'

Your code may not be the best but it looks OK. If you would like to modify it so that you put everything in a multidimensional matrix, here is one way:

myFolder = 'C:\Users\user\Documents\MATLAB\traffic';
filePattern = fullfile(myFolder, '*.jpeg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
  baseFileName = jpegFiles(k).name;
  fullFileName = fullfile(myFolder, baseFileName);
  fprintf(1, 'Now reading %s\n', fullFileName);
  
  % Get the size info from the first image
  if k == 1
    firstImage = imread(fullFileName);
    imageArray = zeros([size(firstImage) length(jpegFiles)]);
  end
  % Now write each image into the array using the index k
  % I am assuming they are RGB images so the images will be 3D as in 256x256x3 where the last dim holds RGB, the three color channels.
  % Now, we are going to use a try catch statement to see which image causes the problem.
  try
      imageArray(:,:,:,k) = imread(fullFileName);
  catch MException
      disp(['Problem image name: ' baseFileName])
      disp(['Size of imageArray = ' num2str(size(imageArray))])
      disp(['size of the problem image = ' num2str(size(imread(fullFileName)))])
  end
  % You don't need the following for now.
  % imshow(imageArray); % Display image.
  % drawnow; % Force display to update immediately.
end

This is going to read all the images and leave the array blank for the indices corresponding to the problem images.

Please let us know if it works now.

Best.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us