MATLAB: Create 3*3 matrix around a given pixel create matrix I have a centroid plotted on a blank image using the command img(a(2),a(1))=1; I would like to create a 3*3 matrix of ones around this pixel as centroid. Can someone tell me how i can achieve this. Thankyou Best Answer One solution:img = zeros(6,7)a = [4 3]img(a(2),a(1)) = 1B = [1 1 1 ; 1 0 1 ; 1 1 1];img2 = conv2(img, B ,'same') Related SolutionsMATLAB: 3*3 matched filter Try this:blurredImage = conv2(single(grayImage), ones(3)/9);imshow(blurredImage, []);% Find where the image was all 1's in a 3x3 box.% The output image will be exactly 1 in that situation.matchingRegions = abs(blurredImage - 1) < 0.0001;% Use axes() or figure() to switch to a new axes if you want.imshow(matchingRegions, []);You might also want to look at normxcorr2(). I have a demo for that if you want it. MATLAB: How to apply median filter to a color image Change thismedfilimg(:,:,1) = medfilt2®;tomedfilimg(:,:,1) = medfilt2(R);and it should be fine. See http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup Related Question3*3 kernal slideHow Can i create 3*3 matrix from 1*3 matrixHow to get back the rgb image from r g b componentHow to implement the 3*3 matrix in a for loopHow to divide an image into 3*3 grids
Best Answer