MATLAB Answers

HOW CAN I CREATE A 3X3 PATCH IN AN IMAGE AND ALSO TAKE THE CENTRE PIXEL FROM ITS EIGHT NEIGHBORHOOD

12 views (last 30 days)
Fodio Longman
Fodio Longman on 20 Mar 2017
Answered: Afiq Azaibi on 23 Mar 2017
Hello,
I need help to create a 3x3 patch of my image and also take the pixel at the centre of its neighborhood.
Many thanks
Longman

Answers (1)

Afiq Azaibi
Afiq Azaibi on 23 Mar 2017
An image functions as a 3 dimensional matrix and in order to index a 3x3 matrix out of an image, you can do the following:
im = imread('peppers.png');
patch = im(1:3,1:3,1:3); %indexes first three rows with first three columns and all three RGB values
center = patch(2,2,:); %this returns the center of each layer.
imshow(patch,'InitialMagnification','fit'); %shows the 9 pixels magnified
If you can describe what you mean by "3x3 patch" regarding an image in more detail, it could help me provide some more relevant code for your use case.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!