Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Do we use spatial filtering or frequency filtering for blurring, edge detection?

By : bibin baby john
Date : July 31 2020, 10:00 AM
To fix the issue you can do For any linear filter (convolution) you can obtain the same result using spatial domain and frequency domain computations. The convolution with a large kernel is usually more efficient to implement by multiplication in the frequency domain. The convolution with a small kernel is likely more efficient to implement directly in the spatial domain, unless one already has the frequency-domain representation (FFT) of the image available.
For any non-linear filter (everything else) you cannot use the frequency domain at all. Fourier analysis is limited to linear systems.
code :

Share :

## Frequency vs spatial domain filtering

By : user3218798
Date : March 29 2020, 07:55 AM
I hope this helps . Assuming that you use imfilter, this function performs a convolution of the original image with the kernel (the gaussian filter image).
For going into the frequency domain and back, fast fourier transform (FFT) algorithms are used, and only an image multiplication is performed in the frequency domain.

## spatial filtering by proximity in R

By : Vikram
Date : March 29 2020, 07:55 AM
around this issue I've written a new version of this function that no longer really follows rMaternII. The input can either be a SpatialPoints, SpatialPointsDataFrame or matrix object.
Seems to work well, but suggestions welcome!
code :
``````filterByProximity <- function(xy, dist, mapUnits = F) {
#xy can be either a SpatialPoints or SPDF object, or a matrix
#dist is in km if mapUnits=F, in mapUnits otherwise
if (!mapUnits) {
d <- spDists(xy,longlat=T)
}
if (mapUnits) {
d <- spDists(xy,longlat=F)
}
diag(d) <- NA
close <- (d <= dist)
diag(close) <- NA
closePts <- which(close,arr.ind=T)
if (nrow(closePts) > 0) {
while (nrow(closePts) > 0) {
closePts <- closePts[-union(which(closePts[,1] == closePts[1,1]), which(closePts[,2] == closePts[1,1])),]
}
}
}
if (nrow(closePts) == 0) {
return(xy)
}
}
``````
``````require(rgeos)
require(sp)
pts <- readWKT("MULTIPOINT ((3.5 2), (1 1), (2 2), (4.5 3), (4.5 4.5), (5 5), (1 5))")

pts2 <- filterByProximity(pts,dist=2, mapUnits=T)

plot(pts)
axis(1)
axis(2)
``````

## Bilateral Filtering preserves the edge, but I want the opposite, an edge -bluring filter?

Date : March 29 2020, 07:55 AM
it should still fix some issue I don't think there is one such filter! But if you want one you have to write one! Here is my Edge Smoothing algorithm! Hope you will find this useful!
code :
``````bool SmoothEdge( Mat mInput_Bgr,Mat &mOutput_Bgr, double amount, double radius, byte Threshold)
{
if(mInput_Bgr.empty())
{
return 0;
}

Mat mInput,mOutput;
Mat mChannel[3];

split(mInput_Bgr,mChannel);

for (int i = 0; i < 3; i++)
{
mInput= mChannel[i];
mOutput.copyTo(mChannel[i]);
}
merge(mChannel,3,mOutput_Bgr);

return true;
}

bool SmoothEdgeSingleChannel( Mat mInput,Mat &mOutput, double amount, double radius, byte Threshold)
{
if(mInput.empty())
{
return 0;
}

Mat mGSmooth,mDiff,mAbsDiff;
mOutput = Mat(mInput.size(),mInput.type());

subtract(mGSmooth,mInput,mDiff);
mDiff*=amount;
threshold(abs(2* mDiff),mAbsDiff,Threshold,255,THRESH_BINARY_INV);

mDiff.setTo(Scalar(0),mAbsDiff);

return true;
}

int main(int argc, char* argv[])
{
string FileName_S="Path\\Image.jpg";
double m_Amount=1.5;
int m_Threshold=0;

Mat mSource_Bgr,mSmoothEdge;

imshow("Source Image",mSource_Bgr);
imshow("Output Image",mSmoothEdge);
}
``````

## How to perfom horizontal rank filtering for edge detection?

By : Dev Crafts
Date : March 29 2020, 07:55 AM
I wish this helpful for you I just tried a code to work for this particular image, but not a general one. Here we have the input image.
code :
``````a = imread('Izy.jpg');
b = imresize(a,0.5);
c = rgb2gray(b);
``````
``````Gpx = edge(c,'canny');
L = bwlabel(Gpx,8);
``````
``````imgstat = regionprops(L,'Area','Eccentricity');
area = [imgstat.Area];
ecc = [imgstat.Eccentricity];
``````
``````label = find((area > 150) & (ecc < 0.95) & (ecc > 0.9));
logical_result = ismember(L,label);
figure;imshow(logical_result)
``````
``````[row, col] = ind2sub([size(c,1), size(c,2)],find(logical_result == 1));
result = c(min(row):max(row),min(col):max(col));
imshow(result);
``````

## Edge Detection in Frequency Domain

By : maximino sy
Date : March 29 2020, 07:55 AM
To fix this issue There are a number of methods out there for this, and one in particular I'll mention is the concentration factor method for detecting edges in spectral signals.
However, these methods are typically used on continuous frequency signals and there's no reason to use this on images. It's slower than convolution kernel based approaches, like Sobel filters for Canny edge detection, and the literature is far more specialized for fields where only frequency based information is given, like in reconstruction from radar or MRI signals.
code :
``````>>> import numpy as np
>>> import cv2
>>> img = np.zeros((8, 8), dtype=np.float32)
>>> img[2:6, 2:6] = 1
>>> img
array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.],
[ 0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.],
[ 0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.],
[ 0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)
``````
``````>>> dct_coeff = cv2.dct(img)
>>> dct_coeff[2:6, 2:6] = 0
``````
``````>>> hp_img = cv2.idct(dct_coeff)
>>> hp_img > 0.75
array([[False, False, False, False, False, False, False, False],
[False, False, False, False, False, False, False, False],
[False, False,  True,  True,  True,  True, False, False],
[False, False,  True, False, False,  True, False, False],
[False, False,  True, False, False,  True, False, False],
[False, False,  True,  True,  True,  True, False, False],
[False, False, False, False, False, False, False, False],
[False, False, False, False, False, False, False, False]], dtype=bool)
``````