how calculate difference 5 adjacent pixels?
10 ビュー (過去 30 日間)
古いコメントを表示
How calculate difference 5 adjacent pixels in under algorithm ?
please give me code in matlab
img = imread(“image path”)
img = rgb2gray(img);
row = no. of pixels in row of image
col = no. of pixels in column of image
for x from 2 to col-6
{
for y from 2 to row-6
{
find the difference of a particular with its adjacent 5 pixels
if difference of intensity > threshold
{ intensity=0 }
else
{ intensity=255 }
}
}
img1 = imsopen(img)
img2 = imerode(img1)
img3 = imclose(img2)
9 件のコメント
DGM
2021 年 11 月 21 日
It's backwards due to the terrible naming convention used by the paper. "row" is the number of columns (length of the rows), not the number of rows.
Image Analyst
2021 年 11 月 21 日
In the paper it says "Code Environment
The above algorithm was written in a MATLAB code and was run on official MATLAB software. "
So, what happened when you contacted the authors and asked for the source code. Did you do that (I would)? What did they say?
回答 (3 件)
Sulaymon Eshkabilov
2021 年 11 月 21 日
Here is the corrected code (see: row vs. col):
for x=2:row-6
for y=2:col-6
difference_of_intensity = abs(m(x,y) - m(x+1, y))+abs(m(x,y) - m(x+2, y))+abs(m(x,y) - m(x+3, y))+abs(m(x,y) - m(x+4, y))+abs(m(x,y) - m(x+5, y));
end
end
0 件のコメント
DGM
2021 年 11 月 21 日
編集済み: DGM
2021 年 11 月 21 日
Here. This implements a sliding-window filter based on your interpretation of what "find the difference of a particular with its adjacent 5 pixels" means.
In this filter, the output pixel is the sum of absolute differences between the pixel and its neighbors in a 5x5 window.
% this isn't the original image, but it's as good as we have
A = rgb2gray(imread('7.png'));
A = imsharpen(imresize(A,2));
% do filter thing
fs = 5;
centerpix = ceil(fs^2/2);
neighbors = [(1:centerpix-1) (centerpix+1:fs^2)];
F = @(x) sum(abs(x(centerpix) - x(neighbors)));
C = nlfilter(im2double(A),[fs fs],F);
[min(C(:)) max(C(:))] % result is poorly-scaled
ans =
0.0235 14.1020
imshow(C,[]) % show the result
No thresholding is performed internally, though it could. It can just as simply be applied afterwards.
How that relates to the operations performed in the paper is anybody's guess. There's no description of threshold selection or the parameters used for subsequent morphological operations.
The core of the paper is undocumented nonsense. It is unclear how the pseudocode relates to any of the described operations in the text or to which examples it applies. The preceding examples regarding sobel and prewitt filters appear to have been simply performed with imfilter() without actually calculating the gradient magnitude or paying particular attention to threshold levels. I don't know what you hope to glean from the results.
0 件のコメント
Image Analyst
2021 年 11 月 21 日
From your diagrams it looks like you want to scan your image with a 5x5 window, and have that window move in "jumps" of 5 pixels. This is different than conv2(), imfilter(), nlfilter(), etc. where the window moves over 1 pixel at a time. To have the filter window move in "jumps" you need blockproc(). I'm attaching several demos for blockproc(). I'm sure you'll be able to modify one to do the operation you want, like max-min to get the range or whatever. From r2017b and later, you can use the bounds() function to get the max and min
3 件のコメント
Image Analyst
2021 年 11 月 22 日
@m madia, use fspecial() to get the filter, then imfilter() to filter the image.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!