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

  • SEARCH
  • Home
  • 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 6931859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:37:56+00:00 2026-05-27T11:37:56+00:00

%% Adaptive Median Filtering – The Code ip1 = imread (‘lena.gif’); %% Undistorted image

  • 0
%% Adaptive Median Filtering - The Code

ip1 = imread ('lena.gif');                  %% Undistorted image
ip = imnoise (ip1,'salt & pepper',0.25);    %% Image corrupted with 'Salt and Pepper Noise'

ip_median_filt1 = medfilt2(ip);             %% Apply median filter to noisy image with window dimensions of 3x3 pixels
ip_median_filt2 = medfilt2(ip,[4,4]);       %% Apply median filter to noisy image with window dimensions of 4x4 pixels
figure(1), clf;
subplot (2, 1, 1), imshow (ip, []);
subplot (2, 1, 2), imshow (ip_median_filt1, []);

%% We now proceed with the adaptive median filtering of the noisy image and 
%% prove that the results are better than those of the standard median filter 
%% shown above

%% Packing zeros around the edge pixels of the noisy input image so as to 
%% allow the facilitate the processing of edge-pixels of the image

ip_edge = zeros (212,276);

ip_convert = double (ip);

%%%%%%%%%% there seems to be error on the following line
ip_edge (11:202, 11:266) = ip_edge (11:202, 11:266) + ip_convert;

smax=9;

for i=11:202
    for j=11:266
        sx=3;
        sy=3;
        while ((sx<=smax) && (sy<=smax))
            ip_edge_min = ip_edge (i, j);
            ip_edge_max = ip_edge (i, j);
            ip_edge_median = median(median(ip_edge((i-floor(sx/2)):(i+floor(sx/2)),(j-floor(sy/2)):(j+floor(sy/2)))));
            for k= (i-floor (sx/2)) :( i+floor (sx/2))
                for l= (j-floor (sy/2)) :( j+floor (sy/2))
                    if ip_edge (k, l) < ip_edge_min
                        ip_edge_min = ip_edge (k, l);
                    end 
                    if ip_edge (k, l) > ip_edge_max
                        ip_edge_max = ip_edge (k, l);
                    end 
                End 
            end 
            A = ip_edge_median - ip_edge_min;
            B = ip_edge_median - ip_edge_max;
            if (A>0) && (B<0)
                C = ip_edge (i, j) - ip_edge_min;
                D = ip_edge (I) - ip_edge_max;
                if (C>0) && (D<0)
                    pledge (i, j) = ip_edge (i, j);
                    break
                else
                    ip_edge (i, j) = ip_edge_median;
                    break
                end 
            else 
                sx=sx+2;
                sy=sy+2;
                if (sx>smax) && (sy>smax)
                    ip_edge(i,j) = ip_edge(i,j);
                end 
            end
        end 
    end 
  end 
end


figure(2), clf;
imshow(ip_edge,[]);

I am getting an error at the line with the %%%%%%%%%%:

??? Error using ==> plus Matrix dimensions must agree.
Error in ==> adaptive at 22 ip_edge (11:202, 11:266) = ip_edge (11:202, 11:266) + ip_convert;

  • 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-05-27T11:37:57+00:00Added an answer on May 27, 2026 at 11:37 am

    Your error has nothing to do with Adaptive filtering. It’s just that the matrix dimensions do not match!

    Tip: you should not have to explicitly specify the dimensions of the image.
    Use something like:

    ip_edge = zeros(size(ip1) + 20);
    ip_edge(11:end-10,11:end-10) = double(ip);
    

    Alternatively you could use the built-in function padarray

    ip_edge = padarray(double(ip), [10 10])
    

    By the way your code is extremely inefficient. Rule #1 of Matlab is: Never loop! Ok, it is not always feasible but it’s what you should aim at.
    Here is a “lean” code for sliding median filtering:

    A = imread('lena.gif');
    fun = @(x) median(x(:));
    B = nlfilter(A,[3 3],fun);
    imshow(A), figure, imshow(B)
    

    Is that what you meant by “adaptive”?
    Good luck in your learning of Matlab 🙂

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

Sidebar

Related Questions

I am trying to implement the adaptive huffman code, but while trying to build
I'm writing a code for adaptive finite element method in 1d. I have an
I've noticed in Apple's accelerometer sample code they use both regular and adaptive low
Is there any C# code/classes/open-source/tools that is recommended for adaptive authentication? Some functions of
UPDATE 2: The code I currentlly have is as follows: paypalplatform.php: https://www.paypal-labs.com/integrationwizard/adaptive/code2.php basic_payment.php: (the
Running on Adaptive Server Enterprise/15.0.3/EBF 17157 ESD#3/P/x86_64/Enterprise Linux/ase1503/2726/64-bit/FBO/ The below code should never enter
I'm trying to convert this adaptive bayesian rating formula into PHP code: see here
Apple has included HTTP Adaptive Bitrate Streaming in the iPhone OS 3.0, in particular
Timsort is an adaptive, stable, natural mergesort. It has supernatural performance on many kinds
I have a adaptive server anywhere network server(version 7.0),it's name is TestServer. Now, Client

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.