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!