Clear Filters
Clear Filters

i need code urgently for my project, please help me

3 views (last 30 days)
i want code for comparison of pixels in an image by considering a 3*3 matrix. for each pixel, a 3*3 matrix around the pixel should be considered and the pixel must be compared with both the diagonals of the considered 3*3 matrix, whether the pixel is greater than all the diagonal elements or not?

Accepted Answer

Image Analyst
Image Analyst on 11 Jan 2019
If you're not turning it in for homework, you can use my code below which uses highly optimized 2-D convolution:
grayImage = imread('cameraman.tif');
subplot(1, 2, 1);
imshow(grayImage, []);
% Do one corner
kernel = [-1,0,0;0,1,0; 0,0,0];
filter1 = conv2(grayImage, kernel, 'same');
% Do another corner
kernel = [0,0,-1;0,1,0; 0,0,0];
filter2 = conv2(grayImage, kernel, 'same');
% Do another corner
kernel = [0,0,0;0,1,0; -1,0,0];
filter3 = conv2(grayImage, kernel, 'same');
% Do another corner
kernel = [0,0,0;0,1,0; 0,0,-1];
filter4 = conv2(grayImage, kernel, 'same');
% Output must have middle pixel greater than all 4 corners.
outputImage = (filter1 > 0) & (filter2 > 0) & (filter3 > 0) & (filter4 > 0);
subplot(1, 2, 2);
imshow(outputImage, []);
0000 Screenshot.png

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!