4

I have the following image in fits format. I want to remove all the stars and other smaller dots from that image using matlab.enter image description here

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 am getting image like this:enter image description here

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:enter image description here

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?

An student
  • 392
  • 1
  • 6
  • 16
  • Just letting you know: this is a very good question in SO, thanks for making the effort of posing the question properly and showing what you tried. – Ander Biguri Oct 17 '16 at 11:53

1 Answers1

4

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:

enter image description here

OUTPUT:

enter image description here

Improvement:

To be more precise it can be useful to compute the parameters of the ellipse.

enter image description here

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);
obchardon
  • 10,614
  • 1
  • 17
  • 33