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

조회 수: 4 (최근 30일)
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

답변 (1개)

Afiq Azaibi
Afiq Azaibi 2017년 3월 23일
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!

Translated by