I have the following image in fits format. I want to remove all the stars and other smaller dots from that image using matlab.
I performed the following matlab operations to remove stars in it.
I = imread('NGC_0253.jpg');
if size(I,3)==3
I=rgb2gray(I);
end
K = imcomplement(I);
L = I-K;
M = medfilt2(L);
imshow(M)
I also try the following:
I = imread('NGC_0253.jpg');
if size(I,3)==3
I=rgb2gray(I);
end
K = imcomplement(I);
L = I-K;
M = bwareaopen(L,1000);
N = medfilt2(M);
imshow(N)
but it also does not satisfy me:
Which is not my objective. My objective is to remove all the stars from the image.
So, What should I do to remove all the stars leaving the galaxy intact from the image?
By using bwareaopen
I get a good result. (I use your second image as input, so you can keep the first part of your code)
I = imread('NGC_0253.jpg');
I = im2bw(I,0.5); %the second parameter correspond to the threshold ∈ [0-1]
I = ~bwareaopen(~I,400); %where 400 = the minimal number of connected pixel needed to not be removed.
imshow(I)
INPUT:
OUTPUT:
Improvement:
To be more precise it can be useful to compute the parameters of the ellipse.
To do that you can use the function fit_ellipse
available on fileexchange.
Iedge = edge(mat2gray(I),'Canny');
[x,y] = find(Iedge');
hold on
A = fit_ellipse(x,y,h);