i need to code for neighboring pixel
Show older comments
hi i need to code for image processing: i have a binary image. If the value of the current pixel is 255, and as soon as it is found out that there exists a neighboring pixel whose value is zero, then the value of this corresponding pixel in the C matrix is assigned the value 127.Similarly, if the value of the current pixel is zero and if there exists a neighboring pixel whose value is 255, then the current pixel (i,j) in matrix C is assigned the value 127. pleas help me.
Answers (3)
Image Analyst
on 18 Apr 2013
For the first question, call imerode(), then subtract from the original binary image. Then set all those pixels to 127. Untested code off the top of my head:
binaryImage = binaryImage - imerode(binaryImage);
grayImage = zeros(size(binaryImage), 'uint8'); % Create an output image.
grayImage(binaryImage) = 127; % This is your output image.
for the second question, basically the same except you call imdilate() and reverse the order of the subtraction:
binaryImage = imdilate(binaryImage) - binaryImage;
grayImage = zeros(size(binaryImage), 'uint8'); % Create an output image.
grayImage(binaryImage) = 127; % This is your output image.
3 Comments
Image Analyst
on 18 Apr 2013
By the way, I saw the tag called edge detection. This is not usually how you'd do edge detection on binary images. You'd use bwperim() or bwboundaries().
fatemeh
on 18 Apr 2013
Image Analyst
on 18 Apr 2013
Then you don't have a binary image at all. You have a grayscale image, and you probably want to use graycomatrix(). Or maybe you just want the Laplacian:
edgeStrengthImage = conv2(double(grayImage), [-1,-1,-1,-1,8,-1,-1,-1,-1]/8, 'same');
That image gives you the average gray level difference between a pixel and its 8 neighbors.
Andrei Bobrov
on 18 Apr 2013
i1 = imdilate(A,ones(3));
l1 = find(A==0);
i2 = i1(l1);
A(l1(i2 == 255)) = 127;
fatemeh
on 18 Apr 2013
0 votes
Categories
Find more on Object Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!