Vikram
Vikram

Reputation: 445

Image labeling and finding centroids in matlab

My problem is that I have a radar image in png format. (Sorry, but i had to remove the image as my colleague says it a copyright infringement of the German Weather Service)

I want to read the image in MATLAB. Then read all the clouds, and label each cloud with a unique index. This means that each pixel belonging to a certain cloud is labeled with the same index i. Calculate the center of area(coa) of each cloud and then I should be able to measure distances between clouds from one coa to another.

Some similar work I know was done in IDL. I tried using that but it would be much easier for me if I'm able to do all this in MATLAB and concentrate more on the result, rather then spend time learning IDL.

So, before jumping in, I want to know if all this is possible in MATLAB. If yes, can you guide me a little on how I can extract the cloud and label them?

Upvotes: 2

Views: 9610

Answers (3)

Eitan T
Eitan T

Reputation: 32920

Yes, of course. This can be done using k-means clustering. You can read about imread and kmeans. The example given in the official documentation of kmeans shows exactly what you need.

For example, if you want to cluster your image into 5 clouds:

%// Read the image
I = imread('clouds.png');
[y, x] = find(I);             %// Obtain all coordinates
y = size(I, 1) - y + 1;       %// Adjust y-coordinates
K = 5;
[idx, c] = kmeans([x, y], K); %// Classify clouds into K clusters

Now idx stores the corresponding cluster indices and c stores the coordinates of the centroids.

To draw the results, you can do something like this:

%// Plot results
figure, hold on
scatter(x, y, 5, idx)         %// Plot the clusters
plot(c(:, 1), c(:, 2), 'r+')  %// Plot centroids
text(c(:, 1) + 10, c(:, 2), num2str((1:K)'), 'color', 'r')  %// Plot cluster IDs

Note that this method requires predetermining the number of clusters K in advance. Alternatively, you can use this tool to attempt to automatically detect the number of clusters.

EDIT: Due to the copyright claim I removed the resulting image.

Upvotes: 1

bla
bla

Reputation: 26069

First do some basic image analysis such as thresholding or median filtering and so forth, to reduce noise if relevant. Then you can use bwlabel to label each cloud with a unique index. The use reigonprops to find the centroids.

Here's a very basic code sample:

d=imread('u09q8.png');
bw = im2bw(d,0.1); % thereshold at 50%
bw = bwareaopen(bw, 10); % Remove objects smaller than 10 pixels from binary image
bw=bwlabel(bw); % label each cloud 
stats=regionprops(bw,'Centroid'); % find centroid coordinates of all labeled clouds

Upvotes: 3

Mark
Mark

Reputation: 8431

Yes it is possible. Regarding the cloud detection, it is a step by step process. It will be based on the algorithm you are going to use. You can start here.

Upvotes: 1

Related Questions