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!