how to set colors for regions in an image?

2 views (last 30 days)
sheno39
sheno39 on 24 Oct 2013
Edited: Walter Roberson on 24 Oct 2013
i have to set different colors for different regions in a same image. In the first step i have calculated the intensity for all pixel using parzen density formula.
Next i had found the neighbour pixel and location having higher intensity value in 8-coordinated size for all pixels in the image. Now i have an variable having locations of maximum pixel of all pixels. i need to give same color for similar location. can anyone help me.. i have given my coding i have done yet.What corrections i have to do?
I=im2double(imread('horse1.bmp'));
I=rgb2gray(I);
imshow(I),figure;
M=[1 1 1;1 1 1;1 1 1]./9;
A=(exp(-((I-conv2(I,M,'same')).^2)./18));
I=(1/2*pi*9).*A;
D = padarray(I,[1 1],0,'both');
s = size(I);
N = padarray(reshape(1:numel(I),s),[1 1],0,'both');
pt = [1 1 1;1 0 1;1 1 1] > 0;
s1 = s+2;
out = zeros(s);
for i=2:s1(1)-1
for j=2:s1(2)-1
D1 = D(i-1:i+1,j-1:j+1);
K = N(i-1:i+1,j-1:j+1);
K = K(pt);
[~,i0] = max(D1(pt));
out(i-1,j-1) = K(i0);
end
end
s=[5,5];
[R C]=ind2sub(s,out);

Answers (0)

Community Treasure Hunt

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

Start Hunting!