Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Find Max Delta of Sliding 3×3 Window Over Matrix

Find Max Delta of Sliding 3×3 Window Over Matrix

PuTI / 2025-01-16
Find Max Delta of Sliding 3×3 Window Over Matrix
Matlab News

I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…

The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7

I have tried with the following code, but it’s clearly off.

A = magic(3);

arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;

for k = 1:9

if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks.I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…

The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7

I have tried with the following code, but it’s clearly off.

A = magic(3);

arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;

for k = 1:9

if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks. I have the code below to find the max delta between a point and its 8 neighbors in a sliding 3×3 window. I do this for the whole matrix input, A. This works fine and correct, but I am wondering if this can be accomplished with several uses of conv2 instead of the imerode/imdilation calls. The computation I’m doing is depicted in the attached image.
% This method works fine…
A = magic(3); % Test case
% This finds the max diff
% between a pixel and its 8 neighbors.
drMin = min(A(:)); drMax = max(A(:)); % Phantom (padding) pts outside of domain are assumed the avg.
padPt = mean([drMin drMax]); % Value to use for padding.
tmp1 = padarray(A,1,padPt,’both’); tmp2 = padarray(tmp1′,1,padPt,’both’); Apad = tmp2′; % Pad matrix.
maxApad = imdilate(Apad,ones(3)) – Apad; % Local max minus the map. Delta from each pt to max neighbor.
minApad = imerode(Apad,ones(3)) – Apad; % Local min minus the map. Delta from each pt to min neighbor.
tmp(:,:,1) = abs(maxApad); tmp(:,:,2) = abs(minApad);
Ctmp = max(tmp,[],3); % Largest of the two gives the max delta from each point to its neighbors!
C = Ctmp(2:end-1,2:end-1); % Remove padding…

The expected result for the magic(3) input is:
7 7 5
6 4 6
5 7 7

I have tried with the following code, but it’s clearly off.

A = magic(3);

arrayTot = zeros(3,3,8);
kernel = zeros([9 1]); kernel(5) = 1;

for k = 1:9

if k ~=5
kernel(k) = -1;
k1 = kernel;
k1 = reshape(k1,[3 3]);
tmp = conv2(A,k1,’same’);
arrayTot(:,:,k) = abs(tmp);
kernel = zeros([9 1]); kernel(5) = 1;
end
end
tst = max(arrayTot,[],3)
Any advice would be appreciated. Thanks. convolution, image processing, imdilate, imerode MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

test one two three four
2025-05-20

test one two three four

Is it possible to make this tiny loop faster?
2025-05-19

Is it possible to make this tiny loop faster?

Solar Wind Battery Hybrid Integration
2025-05-19

Solar Wind Battery Hybrid Integration

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss