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:
Issues with AVIREAD?

Subject: Issues with AVIREAD?

From: GT Johnson

Date: 19 Jul, 2010 15:10:31

Message: 1 of 5

Here is my scenario:

I wrote a piece of code to read in an avi, compute the average intensity over 1000 frames, subtract the average from each frame, and spit out the reassembled, filtered video. When I originally wrote the code the only machine I could get it to run on was a 64 bit Mac running 2009a (because of file size issues I believe, a 1.16 GB avi went in and a 3.84 GB video came out).

Here is my problem:

After running the code successfully on this machine for months I left it for about 6 weeks as I worked elsewhere. When I returned to continue running the code, the same code on the same machine (but now updated to 2009b) ran successfully but spit out an entirely different video (with my signal gone entirely!). I figured it had to do with the software being updated to 2009b, so I found a 32-bit Mac running 2009a and it ran sucessfully for 2 days. I returned on a Monday, and the same code on this machine now would not run successfully at all.

I am an engineer, not a computer scientist, but I need this code to run ASAP! Any thoughts or ideas, I really appreciate it.

Subject: Issues with AVIREAD?

From: Sean

Date: 19 Jul, 2010 17:18:20

Message: 2 of 5

"GT Johnson" <aaron.true@gatech.edu> wrote in message <i21pt7$t5v$1@fred.mathworks.com>...
> Here is my scenario:
>
> I wrote a piece of code to read in an avi, compute the average intensity over 1000 frames, subtract the average from each frame, and spit out the reassembled, filtered video. When I originally wrote the code the only machine I could get it to run on was a 64 bit Mac running 2009a (because of file size issues I believe, a 1.16 GB avi went in and a 3.84 GB video came out).
>
> Here is my problem:
>
> After running the code successfully on this machine for months I left it for about 6 weeks as I worked elsewhere. When I returned to continue running the code, the same code on the same machine (but now updated to 2009b) ran successfully but spit out an entirely different video (with my signal gone entirely!). I figured it had to do with the software being updated to 2009b, so I found a 32-bit Mac running 2009a and it ran sucessfully for 2 days. I returned on a Monday, and the same code on this machine now would not run successfully at all.
>
> I am an engineer, not a computer scientist, but I need this code to run ASAP! Any thoughts or ideas, I really appreciate it.


If you post the code we would stand a better chance of finding the issue. I have 2009a and b on a 64 bit Mac and I'm sure others do as well.

Subject: Issues with AVIREAD?

From: GT Johnson

Date: 20 Jul, 2010 14:25:12

Message: 3 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i221cs$k0$1@fred.mathworks.com>...
> "GT Johnson" <aaron.true@gatech.edu> wrote in message <i21pt7$t5v$1@fred.mathworks.com>...
> > Here is my scenario:
> >
> > I wrote a piece of code to read in an avi, compute the average intensity over 1000 frames, subtract the average from each frame, and spit out the reassembled, filtered video. When I originally wrote the code the only machine I could get it to run on was a 64 bit Mac running 2009a (because of file size issues I believe, a 1.16 GB avi went in and a 3.84 GB video came out).
> >
> > Here is my problem:
> >
> > After running the code successfully on this machine for months I left it for about 6 weeks as I worked elsewhere. When I returned to continue running the code, the same code on the same machine (but now updated to 2009b) ran successfully but spit out an entirely different video (with my signal gone entirely!). I figured it had to do with the software being updated to 2009b, so I found a 32-bit Mac running 2009a and it ran sucessfully for 2 days. I returned on a Monday, and the same code on this machine now would not run successfully at all.
> >
> > I am an engineer, not a computer scientist, but I need this code to run ASAP! Any thoughts or ideas, I really appreciate it.
>
>
> If you post the code we would stand a better chance of finding the issue. I have 2009a and b on a 64 bit Mac and I'm sure others do as well.

Thanks Sean. The code is below.

%%%%% Digital Video Processing %%%%%%%%%%%%%

%% Ths script reads in an avi and filters out backgorund noise %%

clear;
clc;

reader = mmreader('acartiaDown_1.avi');
framesAtATime = 100;
framesToAverage = 1000;
framesInVid = get(reader, 'numberOfFrames');
pixelWidth = get(reader, 'width');
pixelHeight = get(reader, 'height');

clustersOfFrames = floor(framesInVid/framesAtATime);
upperleft = [1277 31]; % pixel coordinates of observation window - open frame 1 and use data probe
lowerright = [602 454];

% Compute Average Intensity Array to Subtract "Grainy" Noise

avgIntensity = zeros(pixelHeight,pixelWidth,3);

for m = 1:(framesToAverage/framesAtATime) % 100 Frames at a time
    
    vid = read(reader,[(framesAtATime*(m-1)+1) (m*framesAtATime)]);
   
    for k = 1:framesAtATime
        
        mov(k).cdata = vid(:,:,:,k);
        mov(k).colormap = [];
        
        for j = upperleft(1):lowerright(1)
            for i = upperleft(2):lowerright(2)
                avgIntensity(i,j,1) = (k-1)/k*avgIntensity(i,j,1)+ 1/k*mov(k).cdata(i,j,1);
                avgIntensity(i,j,2) = (k-1)/k*avgIntensity(i,j,2)+ 1/k*mov(k).cdata(i,j,2);
                avgIntensity(i,j,3) = (k-1)/k*avgIntensity(i,j,3)+ 1/k*mov(k).cdata(i,j,3);
            end
        end
    end
end

avgIntensity = uint8(avgIntensity); % If the data image type is unit8 colors are displayed on the 0-255 range

% figure;
% colormap(gray(256));
% image(avgIntensity);

aviobj = avifile('acartiaDown_1_filt.avi', 'fps', reader.FrameRate, 'compression','None');

for m = 1:clustersOfFrames
    vid = read(reader,[framesAtATime*(m-1)+1 m*framesAtATime]);
    
    for i = 1 : framesAtATime
        
        mov(i).cdata = vid(:,:,:,i); %mov.cdata = pixel, pixel, R....pixel,pixel, G.....pixel,pixel, B
        mov(i).colormap = [];
        mov(i).cdata(:,:,1)= 255 - avgIntensity(:,:,1) + mov(i).cdata(:,:,1); % 0 = BLACK, 255 = WHITE
        mov(i).cdata(:,:,2)= 255 - avgIntensity(:,:,2) + mov(i).cdata(:,:,2);
        mov(i).cdata(:,:,3)= 255 - avgIntensity(:,:,3) + mov(i).cdata(:,:,3);
        
        %%% NEW %%%
        
        mov(i).cdata((255-mov(i).cdata)>=12)=0; % TO DARKEN THE COPEPODS = FIND WHERE THE STRONG
                                                                                    % SIGNAL IS AND MAKE IT PURE BLACK - 10 is noisy, 15 too small
        mov(i).cdata(1:upperleft(2),1:pixelWidth,:) = 0; % Add the border back in for visualization
        mov(i).cdata(1:pixelHeight,1:upperleft(1),:) = 0;
        mov(i).cdata(lowerright(2):pixelHeight,1:pixelWidth,:) = 0;
        mov(i).cdata(1:pixelHeight,lowerright(1):pixelWidth,:) = 0;
    end
    
    aviobj = addframe(aviobj,mov);
end
                
aviobj = close(aviobj);

Subject: Issues with AVIREAD?

From: Sean

Date: 20 Jul, 2010 15:34:04

Message: 4 of 5

"GT Johnson" <aaron.true@gatech.edu> wrote in message <i24bk8$177$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i221cs$k0$1@fred.mathworks.com>...
> > "GT Johnson" <aaron.true@gatech.edu> wrote in message <i21pt7$t5v$1@fred.mathworks.com>...
> > > Here is my scenario:
> > >
> > > I wrote a piece of code to read in an avi, compute the average intensity over 1000 frames, subtract the average from each frame, and spit out the reassembled, filtered video. When I originally wrote the code the only machine I could get it to run on was a 64 bit Mac running 2009a (because of file size issues I believe, a 1.16 GB avi went in and a 3.84 GB video came out).
> > >
> > > Here is my problem:
> > >
> > > After running the code successfully on this machine for months I left it for about 6 weeks as I worked elsewhere. When I returned to continue running the code, the same code on the same machine (but now updated to 2009b) ran successfully but spit out an entirely different video (with my signal gone entirely!). I figured it had to do with the software being updated to 2009b, so I found a 32-bit Mac running 2009a and it ran sucessfully for 2 days. I returned on a Monday, and the same code on this machine now would not run successfully at all.
> > >
> > > I am an engineer, not a computer scientist, but I need this code to run ASAP! Any thoughts or ideas, I really appreciate it.
> >
> >
> > If you post the code we would stand a better chance of finding the issue. I have 2009a and b on a 64 bit Mac and I'm sure others do as well.
>
> Thanks Sean. The code is below.
>
> %%%%% Digital Video Processing %%%%%%%%%%%%%
>

> upperleft = [1277 31]; % pixel coordinates of observation window - open frame 1 and use data probe
> lowerright = [602 454];

The problem lies with these two inputs and the for loop below!

> % Compute Average Intensity Array to Subtract "Grainy" Noise
>
> avgIntensity = zeros(pixelHeight,pixelWidth,3);
>
> for m = 1:(framesToAverage/framesAtATime) % 100 Frames at a time
>
> vid = read(reader,[(framesAtATime*(m-1)+1) (m*framesAtATime)]);
>
> for k = 1:framesAtATime
>
> mov(k).cdata = vid(:,:,:,k);
> mov(k).colormap = [];
>

Here:
> for j = upperleft(1):lowerright(1)
%NOTE upperleft(1) = 1277,lowerright(1)=602) this for loop is never entered and thus average intensity is black.
> for i = upperleft(2):lowerright(2)
> avgIntensity(i,j,1) = (k-1)/k*avgIntensity(i,j,1)+ 1/k*mov(k).cdata(i,j,1);
> avgIntensity(i,j,2) = (k-1)/k*avgIntensity(i,j,2)+ 1/k*mov(k).cdata(i,j,2);
> avgIntensity(i,j,3) = (k-1)/k*avgIntensity(i,j,3)+ 1/k*mov(k).cdata(i,j,3);
> end
> end
> end
> end
>
> avgIntensity = uint8(avgIntensity); % If the data image type is unit8 colors are

imtool(avgIntensity) %you'll see it's all zeros

Subject: Issues with AVIREAD?

From: GT Johnson

Date: 21 Jul, 2010 15:47:05

Message: 5 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i24flc$23n$1@fred.mathworks.com>...
> "GT Johnson" <aaron.true@gatech.edu> wrote in message <i24bk8$177$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i221cs$k0$1@fred.mathworks.com>...
> > > "GT Johnson" <aaron.true@gatech.edu> wrote in message <i21pt7$t5v$1@fred.mathworks.com>...
> > > > Here is my scenario:
> > > >
> > > > I wrote a piece of code to read in an avi, compute the average intensity over 1000 frames, subtract the average from each frame, and spit out the reassembled, filtered video. When I originally wrote the code the only machine I could get it to run on was a 64 bit Mac running 2009a (because of file size issues I believe, a 1.16 GB avi went in and a 3.84 GB video came out).
> > > >
> > > > Here is my problem:
> > > >
> > > > After running the code successfully on this machine for months I left it for about 6 weeks as I worked elsewhere. When I returned to continue running the code, the same code on the same machine (but now updated to 2009b) ran successfully but spit out an entirely different video (with my signal gone entirely!). I figured it had to do with the software being updated to 2009b, so I found a 32-bit Mac running 2009a and it ran sucessfully for 2 days. I returned on a Monday, and the same code on this machine now would not run successfully at all.
> > > >
> > > > I am an engineer, not a computer scientist, but I need this code to run ASAP! Any thoughts or ideas, I really appreciate it.
> > >
> > >
> > > If you post the code we would stand a better chance of finding the issue. I have 2009a and b on a 64 bit Mac and I'm sure others do as well.
> >
> > Thanks Sean. The code is below.
> >
> > %%%%% Digital Video Processing %%%%%%%%%%%%%
> >
>
> > upperleft = [1277 31]; % pixel coordinates of observation window - open frame 1 and use data probe
> > lowerright = [602 454];
>
> The problem lies with these two inputs and the for loop below!
>
> > % Compute Average Intensity Array to Subtract "Grainy" Noise
> >
> > avgIntensity = zeros(pixelHeight,pixelWidth,3);
> >
> > for m = 1:(framesToAverage/framesAtATime) % 100 Frames at a time
> >
> > vid = read(reader,[(framesAtATime*(m-1)+1) (m*framesAtATime)]);
> >
> > for k = 1:framesAtATime
> >
> > mov(k).cdata = vid(:,:,:,k);
> > mov(k).colormap = [];
> >
>
> Here:
> > for j = upperleft(1):lowerright(1)
> %NOTE upperleft(1) = 1277,lowerright(1)=602) this for loop is never entered and thus average intensity is black.
> > for i = upperleft(2):lowerright(2)
> > avgIntensity(i,j,1) = (k-1)/k*avgIntensity(i,j,1)+ 1/k*mov(k).cdata(i,j,1);
> > avgIntensity(i,j,2) = (k-1)/k*avgIntensity(i,j,2)+ 1/k*mov(k).cdata(i,j,2);
> > avgIntensity(i,j,3) = (k-1)/k*avgIntensity(i,j,3)+ 1/k*mov(k).cdata(i,j,3);
> > end
> > end
> > end
> > end
> >
> > avgIntensity = uint8(avgIntensity); % If the data image type is unit8 colors are
>
> imtool(avgIntensity) %you'll see it's all zeros

Thanks for looking at it. The code is actually correct for what I want it to do, only filter a certain geometric area and leave the rest black. The code as is ran correctly and did exactly what I wanted it to do previously. I believe the problem is a software/hardware thing.

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