normalization image, normalization distance pixels

Hello,
i have image
when I use my code:
img = imread('obraz.bmp');
img = rgb2gray(img);
imshow(img);
%%normalization
img = ( img - min(img(:)) ) ./ ( max(img(:)) - min(img(:)) );
img = ~img;
[m n]=size(img)
P = [];
for i=1:m
for j=1:n
if img(i,j)==1
P = [P ; i j];
end
end
end
size(P);
MON=P;
[IDX,ctrs] = kmeans(MON,3);
clusteredImage = zeros(size(img));
clusteredImage(sub2ind(size(img) , P(:,1) , P(:,2)))=IDX;
imshow(label2rgb(clusteredImage))
my output is
as I am to normalize the image? when I want to output as
Thank for you help

回答 (2 件)

Image Analyst
Image Analyst 2014 年 4 月 1 日

1 投票

Get rid of all that. It's a totally wrong approach. You don't need normalization or building up a list of white pixels. Simply threshold the image and label it and apply colors.
rgbImage = imread('obraz.bmp');
grayImage = rgbImage(:,:,2); % Extract green channel.
binaryImage = grayImage > 128;
labeledImage = bwlabel(binaryImage);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
imshow(labeledImage, []);
Of course if you like really compact code, the 2nd, 3rd, and 4th lines can be combined into one line.

9 件のコメント

Tomas
Tomas 2014 年 4 月 1 日
I need to normalize distance pixels in image,
I want black pixels were clustered, I must normalize distance pixels.
Image Analyst
Image Analyst 2014 年 4 月 1 日
What you say is unclear. Do you want the distance of every single black pixel to every single other black pixel? Or do you want the distance between closest black pixels? If it's the latter, check out bwdist(). I don't see any reason for the former. I also don't know what "normalizing" means in the context you show.
Tomas
Tomas 2014 年 4 月 1 日
編集済み: Tomas 2014 年 4 月 1 日
As the image above, i want to have 4 clusters, I gotta have this output
each color is one cluster. My problem is, I have output now
I don"t know good English, it's hard to explain,
the thing is, when I look at the picture to be logically correct clusters. I need image preprocessing, that I might gain the relevant matrix of the image that I can use for clustering
Image Analyst
Image Analyst 2014 年 4 月 1 日
See attached code (in blue below the image) to produce the image below.
Tomas
Tomas 2014 年 4 月 1 日
I have to use kmeans, I know that your way is better, but I have to use clustering
Image Analyst
Image Analyst 2014 年 4 月 1 日
I don't have the stats toolbox so I can't help you. kmeans seems like it would fail quite easily and often so I don't know why you'd use it instead of something that is robust and foolproof.
Tomas
Tomas 2014 年 4 月 1 日
for example, this image, each shape a different color
Image Analyst
Image Analyst 2014 年 4 月 1 日
Is the shape the white objects or the black objects? Either way, it's trivial with labeling and difficult and faulty with kmeans. If you look at the x,y locations of the points then the centroid of the circle is really close to the centroids of the polygons and the polygon pixels go very near the centroid of the circle and might be classified as circle instead of polygons. Good example of why kmeans is not good for connected components labeling.
Tomas
Tomas 2014 年 4 月 1 日
編集済み: Tomas 2014 年 4 月 1 日
Objects are black, my again makes no sense at all
normalized cuts,How is it used?

サインインしてコメントする。

Arshad Ali
Arshad Ali 2017 年 5 月 10 日

0 投票

Can any one please help me how to normalized pixel area being consumed by each colour. (Normalized area consumed by red colour=No of pixels of Red/( Total no of pixels in the image)

1 件のコメント

Image Analyst
Image Analyst 2017 年 5 月 10 日
See color segmentation demos. Once you have a binary image that defines what pixels you consider to be "red", you simply divide the sum of true/1/white pixels in it by the number of pixels in the image.

サインインしてコメントする。

質問済み:

2014 年 4 月 1 日

コメント済み:

2017 年 5 月 10 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by