Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:50:04+00:00 2026-06-08T12:50:04+00:00

this post is related to my previous question : image processing in matlab as

  • 0

this post is related to my previous question : image processing in matlab
as I have uploaded my algorithme there.
the think is that I am trying to change the filtering part of the code.
in matlab filter.m function can accpet filter(B, A, my pixels evolutions in Time) and it return me the filtered values.
but at the moment I have to pass the the whole time series together.

but the problem is that now I want to change the code in a way instead of passing the whole timeseries into the filter, I want to pass one value at a time, but I want filter function treat the value like the nth value not the first valu.
I have created a sudo code, as I am injecting one picture into the code, but I dont know how can change the filtering part., any body has any idea??

clear all
j=1;
for i=0:3000
  str = num2str(i);
  str1 = strcat(str,'.mat');
  load(str1);
  D{j}=A(20:200,130:230);
  j=j+1;
end
N=5;
w = [0.00000002 0.05;0.05 0.1;0.1 0.15;0.15 0.20;
     0.20 0.25;0.25 0.30;0.30 0.35;0.35 0.40;
     0.40 0.45;0.45 0.50;0.50 0.55;0.55 0.60;
     0.60 0.65;0.65 0.70;0.70 0.75;0.75 0.80;
     0.80 0.85;0.85 0.90;0.90 0.95;0.95 0.99999999];
for ind=1:20
  wn = w(ind,:);
  [b,a] = butter(N,wn);
  bCoeff(ind,:)=b;
  aCoeff(ind,:)=a;
end

ts=[];
sumLastImages=[];
for k=1:10 %number of images
  for bands=1:20 %number of bands
    for i=1:10 %image h
      for j=1:10 %image w
        pixelValue = D{k}(i,j);          
        % reflectivity elimination        
        % for the current pixel, have the summation of the same position from before 
        % images and create a mean value base on the temporal values
        sumLastImages(i,j)=pixelValue+sumLastImages(i,j);
        meanValue = sumLastImages(i,j)/k;

        if(meanValue==0)            
          filteredimages{bands}(i,j)=0; 
          continue;
        else
          pixel_calculated_meanvalue = pixelValue/meanValue; 
        end                      
        % filter part that need to be changed, and because we are adding 
        % one value then the reutrn of the filter is one too         
        ts_f = filter(bCoeff(bands,:), aCoeff(bands,:), ...
                      pixel_calculated_meanvalue);                         
        filteredimages{bands}(i,j)=ts_f;            
      end     
    end       

    finalImagesSummation{bands}(:,:) = ...
      (filteredimages{bands}(:,:)^2)+finalImagesSummation{bands}(:,:);
    finalImages{bands}(:,:)=finalImagesSummation/k;
  end
end

EDIT
I managed to change the code like this, which now I load the fist 200 images, and after that I am able to inject the images one by one into the filter, but now the problem is that I am getting "Out of memory. Type HELP MEMORY for your options." error for big
images.
here is my code any idea to efficent the code :

%%
cd('D:\MatlabTest\06-06-Lentils');
clear all

%%

N=5;
W = [0.0 0.10;0.10 0.20;0.20 0.30;0.30 0.40;
     0.40 0.50;0.50 0.60 ;0.60 0.70;0.70 0.80 ;
     0.80 0.90;0.90 1.0];

[bCoeff{1},aCoeff{1}] = butter(N,0.1,'Low');
for ind=2:9
  wn = W(ind,:);
  [b,a] = butter(N,wn);
  bCoeff{ind}=b;
  aCoeff{ind}=a;
end
[bCoeff{10},aCoeff{10}] = butter(N,0.9,'high');

%%
j=1;

D = zeros(200,380,320);

T = 200;
K = 0:399;
l = T+1;
Yout = cell(1,10);
figure;

for i = 1:length(K)-200
  disp(i)

  if i == 1
    for j = 1:T
      str = int2str(K(1)+j-1);
      str1 = strcat(str,'.mat');
      load(str1);
      D(j,1:380,1:320) = A;
    end

  else

    str = int2str(l);
    str1 = strcat(str,'.mat');
    load(str1);

    temp = D(2:200,1:380,1:320) ;
    temp(200,1:380,1:320) = A;
    D = temp;
    clear temp
    l = l +1;

  end


  for p = 1:380
    for q = 1:320
      x = D(:,p,q) - mean(D(:,p,q));

      for k = 1:10
        temp = filter(bCoeff{k},aCoeff{k},x);
        if i == 1
          Yout{k}(p,q) = mean(temp);
        else
          Yout{k}(p,q) = (Yout{k}(p,q)  + mean(temp))/2;
        end
      end
    end
  end

  for k = 1:10
    subplot(5,2,k)
    subimage(Yout{k}*1000,[0 255]);
    color bar
    colormap jet
  end
  pause(0.01);
end

disp('Done Loading...')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:50:05+00:00Added an answer on June 8, 2026 at 12:50 pm

    No need to rewrite the filter function, there is a simple solution!

    If you want to feed filter with one sample at a time, you need to pass the state parameters as well so that each input sample is processed depending on its predecessor. After filtering, the new state is actually returned as a second parameter, so that most of the work is already done by MATLAB for you. This is good news!

    For the sake of readability, allow me to temporarily replace your variable names with simple letters:

    a = aCoeff(bands, :);    
    b = bCoeff(bands, :);
    x = pixel_calculated_meanvalue;
    

    ts_f is represented by y.

    And so, this:

    y = filter(b, a, x);
    

    is actually equivalent to this:

    N = numel(x);
    y = zeros(N, 1);                             %# Preallocate memory for output
    z = zeros(max(length(a), length(b)) - 1, 1); %# This is the initial filter state
    for i = 1:N
        [y(i), z] = filter(b, a, x(i), z);
    end
    

    You can check for yourself that the result is the same!

    For your example, the code would be:

    N = numel(pixel_calculated_meanvalue);
    ts_f = zeros(N, 1);
    z = zeros(max(length(aCoeff(bands, :)), length(bCoeff(bands, :))) - 1, 1); 
    for i = 1:N
        [ts_f(i), z] = filter(bCoeff(bands, :), aCoeff(bands, :), ...
            pixel_calculated_meanvalue(i), z);
    end
    

    With this method you can process one input sample at a time, just make sure you store the last filter state after every filter call. If you plan on using multiple filters, you’ll have to store a state vector per filter!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to my previous post Image Processing Algorithm in Matlab in
This question is related to a previous post . Is there something comparable to
This question is related with one of my earlier questions.. Previous Post In there
This question is related to the previous post. How to save file and read
This is a follow-up question related to my previous post . Below is a
This is related to a previous question I asked with Jquery. If I have
This question is in continuation to my previous post located here . Since there
This is semi-related to my previous question . As that previous question states, I
This is closely related to a previous question i asked. I have a many-to-many
This post relates to a previous that i posted but the question is different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.