i need to code for neighboring pixel
显示 更早的评论
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.
回答(3 个)
Image Analyst
2013-4-18
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 个评论
Image Analyst
2013-4-18
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
2013-4-18
Image Analyst
2013-4-18
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
2013-4-18
i1 = imdilate(A,ones(3));
l1 = find(A==0);
i2 = i1(l1);
A(l1(i2 == 255)) = 127;
类别
在 帮助中心 和 File Exchange 中查找有关 Object Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!