Unable to fully fill features with thresholding - matlab

I am using MATLAB to analyze some features on a grayscale image through thresholding. I have the following code snippet which is able to identify most of the features of interest (an example is attached). However, imfill is unable to fully fill larger features and thus creates an issue later on when I try to measure feature characteristics. I tried using a higher connectivity value like 8 but that did not help. Any ideas on how to get around this issue is greatly appreciated.
filename = 'test.tif';
I = imread(filename);
bw = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',0.7);
bw = bwareaopen(bw,20);
se = strel('disk',3);
bw = imclose(bw,se);
bw = imfill(bw,'holes');
imshowpair(bw,I,'montage');
t = title('bw vs. original');

Related

image inpainting | inpaintCoherent()

The task is to inpaint the timestamp of the following picture. I use MATLAB's inpaintCoherent, but the result isn't satisfactory. I have attached the original image, the mask, and the inpainted image.
Here is the MATLAB code.
bill = imread('Billiards_ref.png');
mask = imread('mask.png');
bill_inpainted = inpaintCoherent(bill, logical(mask));
imshowpair(bill, bill_inpainted, 'montage')
What image pre or post-processing can I do to improve the quality of the inpainting?
The original image
The mask image
The inpainted image
You may want to consider blurring your mask image a bit prior to the use of inpaintCoherent. This will require some trial and error to see how much smoothing will give your the best image. Based on the images you have posted in your question, here is what I can suggest and the results:
bill = imread('Billiards_ref.jpg'); % Image you included is a jpg file
mask = imread('mask.png');
% Create a blurred mask using a 2D Gaussian kernel with std dev std_dev (in pixel units)
std_dev = 1; % You may want to change this for different images depending on what the resolution of the original mask is
mask_bl = imgaussfilt(double(mask), std_dev);
bill_inpainted = inpaintCoherent(bill, logical(mask_bl));

Motion Deblur using Matlab

I learnt about deconvlucy and deconvwnr techniques to remove motion blur and they work pretty well on simulated deblurred images. Hence, I tried to check this algorithm on real footages captured with mobile. I also stabilised video using Movavi video editor.
And here is my code:
I = imread('mobile_blur13.png');
imshow(I);
lengthmin = 12;
lengthmax = 15;
thetamin =331;
thetamax=335;
figure;
for length = lengthmin:0.2:lengthmax
for theta = thetamin:0.5:thetamax
PSF = fspecial('motion',length,theta);
res = deconvlucy(I,PSF,100);
res2 =deconvreg(I,PSF);
noise_var = 0;
signal_var = var(double(I(:)));
estimated_nsr = noise_var/signal_var;
res1= deconvwnr(I,PSF,estimated_nsr);
%res = medfilt2(rgb2gray(res));
f = imfilter(res, fspecial('average', [3 3]));
imshow(f);
end
end
But, am getting very bad results. May I know what am doing wrong.
Here is a image:
Thanks in advance
Deblurring an image with a simulated blur is very different from deblurring an actual camera captured photos.
Motion blur due to camera motion can significantly degrade the quality of an image. Since the path of the camera motion can be arbitrary, deblurring of motion blurred images is a hard problem. There are several methods to deal with this problem such as blind restoration or optical correction using stabilized lenses.
The solution is to use blind deconvolution and the deconvblind command.
https://www.mathworks.com/help/images/ref/deconvblind.html

How to extract houghpeaks for each street light after thresholding and image labelling?

I'm doing my final year project on image processing in matlab. My project is identifying which lights are 'off' in a street in a static image.
These are the sequences of steps that i'm following :
I have done thresholding and image labelling i.e, labelling each light source from 1 and so on in thresholded image. The corresponding code is
I = imread('st.jpg');
imshow(I);
G = rgb2gray(I);
imshow(G);
BW = im2bw(G,0.7);
imshow(BW);
f = fspecial('average',3);
I1 = filter2(f,BW,'same');
imshow(I1);
[Lw, nw] = bwlabel(I1);
imtool(Lw,[]);
s = strel('disk',5);
O = imopen(Lw,s);
figure, imshow(O,[]);
Now I need to create a data base of each light source and compare the test image(image with one/many light source off) with reference image to identify which one is off and display it.
Since houghpeaks for each light source is different. I want to extract houghpeaks for each light source using hough transform.
I have searched for it so much but i dint get anything. If someone helps me it would be a great help for my project.
Thanks already.

Over-watershedding image

I'm having trouble separating cells in microscope images. When I apply a watershed transform I end up cutting up cells into many pieces and not merely separating them at the boundary/minimum.
I am using the bpass filter from http://physics.georgetown.edu/matlab/code.html.
bp = bpass(image,1,15);
op = imopen(bp,strel('ball',10,700));
bw = im2bw(bp-op,graythresh(bp-op));
bw = bwmorph(bw,'majority',10);
bw = imclearborder(bw);
D = bwdist(~bw);
D = -D;
D(~bw) = -Inf;
L = watershed(D);
mask = im2bw(L,1/255);
Any ideas would be greatly appreciated! You can see that my cells are being split apart too much in the final mask.
Here is the kind of image I'm trying to watershed. It's a 16bit image so it looks like it is all black.
Starting fluorescent image
Final image mask:
I separated the cells manually here:
Finding the centers of the cells should be relatively straight-forward: finding a local maxima of the intensity. Using these points as seeds for the watershed, you might find this tutorial useful.
Some morphologcal operations you might find useful are:
- imimposemin - forcing a seed point to be a local min when computing the watershed transform.
- imregionalmax - finding local maxima of intensity image.

How to fill empty parts of a projected image?

When i projected a 3D model on a 2D plan (Perspective projection) the result of the projection appeared as the following image.
and i need to fill empty points in this image to look like this one
i wonder that i can find a good way to fill this points with a professional way using any image processing algorithms using matlab
Code in Mathematica. Matlab surely has the equivalent image transformations.
Let's see how both images fit:
As you can see, the neck is a bit Hulkish ... otherwise the result is quite good
Here is a MATLAB version somewhat equivalent to #belisarius answer:
I = double(imread('http://i.stack.imgur.com/sedZH.png'));
BW = im2bw(I,graythresh(I));
BW = imerode(BW,strel('square',2*3+1));
BW = imfilter(BW, fspecial('average',10));
BW = imdilate(BW,strel('square',2*3+1));
BW = imcomplement(BW);
imshow(BW)