How can I remove the texture from an image using matlab? - matlab

How can I use the fourier transform to find out the frequency components which are responsible for the texture on the surface?
Then I have to remove them to have a smooth surface without texture.
This is the image.
Thanks

If you use Fourier Transform and analyze frequency components, then removing high frequency components of the image gives a close effect of low pass filter. However, it does not seem natural since you also manipulate the phase of the image. As people suggest, I also advise low pass filter. More specifically, if you want the color of the given image, you may want to try Gaussian Filter.

Related

How to fit an image feature to a curve

I process a bunch 2D each having a sinusoidal feature randomly located in it:
Whereas the amplitude and the period of the sine are known in advance, the exact position is not.
I want to find an exact position of the sine in each image using MATLAB. Standard fitting techniques like Surface Fit won't work here because I only need to fit one feature, not the whole image.
The best idea that comes to my mind is to generate a reference image with a sine with a known location, and then use cross-corrrelation (xcorr2) to find the offset between the two. Maybe you could suggest any faster and simpler solution?

Smoothing a noisy image then sharpening

I have been trying to restore a noisy image on MATLAB. I started with an original grayscale image of mine and then I applied Gaussian noise. I then took the noisy image and applied a Gaussian smoothing filter. After applying the smoothing filter, I applied a Laplacian filter over the Gaussian Blurred image and got a black image with some "edges" showing. What I am confused about is what to do next. I tried using the imadd function on MATLAB and adding the Gaussian blurred image with output of the Laplacian filter, but my results are not as good as I thought they would be. The "restored" image is nowhere near as good as I thought it would be!
Am I doing this correctly?
#eigenchris basically nailed it right on the head, but I would like to elaborate some more on why we believe this is a bad idea. Blurring the image removes high frequency content (i.e. edges). If you try to apply a high-pass filter like the Laplacian to the low-pass result, you will probably not get anything at all.
Specifically, the high frequency components were removed when you Gaussian blurred the image, and so if you apply a high-pass filter to an image with high frequency components already removed, you will probably get an almost zero output.
The moral of this story is that you can't sharpen an already blurred image because it relies on high frequency information to facilitate the sharpening. You are essentially amplifying the high frequency content so that the edges stand out more, and hence it is a sharpened result.
One thing I could suggest is to perhaps look into deconvolution techniques, like the Wiener filter. The Wiener filter essentially tries to undo the effects performed by a filter done on an image.
One great example can be found on this MathWorks link: http://www.mathworks.com/help/images/examples/deblurring-images-using-a-wiener-filter.html
As such, blur the image to eliminate any noise, then reverse the blur with Wiener filtering so you can get an OK version of the original, then sharpen that reconstructed image.
Good luck!

MATLAB: Using hough transform to detect circle

I am writing a matlab code that takes in a photo and detects the circular object. For example, the function takes a picture of a peach (circular object) as an input and will return the same image with the peach circled.
Currently, I am using hough transform, utilizing imfindcircles function. However, this function requires me to specify radius range and some sort of sensitivity/threshold value. These values differ for different sizes of image and round objects. So, to get the desired output, I will have to manually change these values for each input image, which is not what I want. I'm going to use this function on 100+ images, so it's impossible for me to do this manually.
My question is is there any way I can make my circular object detection function less manual and possibly completely automatic (does not require me to input any values, just the image)?
Complexity of circle detection
The Hough transform is a voting procedure that requires assumptions be made about the minimum and maximum radii of your circles. Generally speaking using the Randomized Hough Transform for Circles you would pick three-points and then try to form a circle and check if the radius is within the desired range. Running this for a good number of iterations you should find peaks (multiple hits) in your accumulator matrix that represent circles. If you didn't make any assumptions about object size I think it is obvious this method wouldn't work.
Do some routine pre-processing to adjust for contrast and brightness e.g. contrast stretching, histogram equalization. If you might have some noise in the images, then apply bit of gaussian smoothing as well.
Normalizing images this way will reduce inter-image variance and help you with setting thresholds.
the Hough Transform can be used to detect circles, lines, etc.You can refer the demos in Matlab. There are several cases for the application of Hough Transform.

image focus and FFT

I am a new to Matlab and I have a project that involves image processing.
I have a number of RGB images and I need to find a way to separate the out of focus from the in focus images. I do not need to correct the focus of the out of focus ones, I just need to find which are out of focus and remove them. I have done FFT2 to the image and then used the radial average of the image of the power spectrum to see if there is a difference between the in focus or out of focus but I do not see a difference between the two.
I decided to use the gradient of the image
[gradx,grady]=gradient(image)
and then take the magnitude
new_image=sqrt((gradx.^2)+(grady.^2))
and try to do the FFT2 using the new_image now instead of the image. The power spectrum does not look like what I expect so I am not sure if I should do the FFT2 on the new_image of the gradx and grady separately. Has anyone have any thoughts about whether this is the right way to do this?
I was also thinking that instead of using the gradient to use a Sobel mask
mask=fspecial('sobel')
mask_x=imfilter(image,mask)
mask_y=imfilter(image,mask')
new_image=sqrt((mask_x.^2)+(mask_y.^2))
and then do FFT2 in the new_image but again the power spectrum is not right. I expect it to start from zero and instead it starts from the highest value and drops exponentially.
Has anyone tried to classify images using this method? Thank you for reading.
A DCT, instead of an FFT/DFT, will get rid of any high frequency discontinuities between the opposite edges of your images.

Remove paper texture pattern from a photograph

I've scanned an old photo with paper texture pattern and I would like to remove the texture as much as possible without lowering the image quality. Is there a way, probably using Image Processing toolbox in MATLAB?
I've tried to apply FFT transformation (using Photoshop plugin), but I couldn't find any clear white spots to be paint over. Probably the pattern is not so regular for this method?
You can see the sample below. If you need the full image I can upload it somewhere.
Unfortunately, you're pretty much stuck in the spatial domain, as the pattern isn't really repetitive enough for Fourier analysis to be of use.
As #Jonas and #michid have pointed out, filtering will help you with a problem like this. With filtering, you face a trade-off between the amount of detail you want to keep and the amount of noise (or unwanted image components) you want to remove. For example, the median filter used by #Jonas removes the paper texture completely (even the round scratch near the bottom edge of the image) but it also removes all texture within the eyes, hair, face and background (although we don't really care about the background so much, it's the foreground that matters). You'll also see a slight decrease in image contrast, which is usually undesirable. This gives the image an artificial look.
Here's how I would handle this problem:
Detect the paper texture pattern:
Apply Gaussian blur to the image (use a large kernel to make sure that all the paper texture information is destroyed
Calculate the image difference between the blurred and original images
EDIT 2 Apply Gaussian blur to the difference image (use a small 3x3 kernel)
Threshold the above pattern using an empirically-determined threshold. This yields a binary image that can be used as a mask.
Use median filtering (as mentioned by #Jonas) to replace only the parts of the image that correspond to the paper pattern.
Paper texture pattern (before thresholding):
You want as little actual image information to be present in the above image. You'll see that you can very faintly make out the edge of the face (this isn't good, but it's the best I have time for). You also want this paper texture image to be as even as possible (so that thresholding gives equal results across the image). Again, the right hand side of the image above is slightly darker, meaning that thresholding it well will be difficult.
Final image:
The result isn't perfect, but it has completely removed the highly-visible paper texture pattern while preserving more high-frequency content than the simpler filtering approaches.
EDIT
The filled-in areas are typically plain-colored and thus stand out a bit if you look at the image very closely. You could also try adding some low-strength zero-mean Gaussian noise to the filled-in areas to make them look more realistic. You'd have to pick the noise variance to match the background. Determining it empirically may be good enough.
Here's the processed image with the noise added:
Note that the parts where the paper pattern was removed are more difficult to see because the added Gaussian noise is masking them. I used the same Gaussian distribution for the entire image but if you want to be more sophisticated you can use different distributions for the face, background, etc.
A median filter can help you a bit:
img = imread('http://i.stack.imgur.com/JzJMS.jpg');
%# convert rgb to grayscale
img = rgb2gray(img);
%# apply median filter
fimg = medfilt2(img,[15 15]);
%# show
imshow(fimg,[])
Note that you may want to pad the image first to avoid edge effects.
EDIT: A smaller filter kernel than [15 15] will preserve image texture better, but will leave more visible traces of the filtering.
Well i have tried out a different approach using Anisotropc diffusion using the 2nd coefficient that operates on wider areas
Here is the output i got:
From what i can See from the Picture, the Noise has a relatively high Frequency Compared to the image itself. So applying a low Pass filter should work. Have a look at the Power spectrum abs(fft(...)) to determine the cutoff Frequency.