-1

I have a gray leveled image and want to find the zone where a specific color (for example black) is more denser. As this issue is part of a bigger project I need to program it in java, but I am not finding an adequate algorithm.

  • 1
    Add a java tag if you want a java answer. What format is the image in? Is it in a file? Do you know how to read a file in Java? Have you tried writing any code yet? If so, what? – doctorlove Aug 28 '13 at 08:40
  • 1
    If you are starting with image processing I really recomend you to start writing your code in Matlab and then, jump to another language (java in your case) – karl71 Aug 28 '13 at 08:41
  • do you want a coarser quantization of the image? or a grey-level based segmentation of the image? if you want segmentation based on color similarity you should check out mean-shift segmentation. See http://stackoverflow.com/questions/4831813/image-segmentation-using-mean-shift-explained – Shai Aug 28 '13 at 09:00
  • I am treating the image as a 2D array so I have 0-255 numerical values and in this case I want to find all the groups of the array with value 0. – user2724554 Aug 28 '13 at 09:15

2 Answers2

1

You should use K-Means to find clusters in your image. For instance your dataset should be Position X, Y, Z and value of gray.

Then runs the algorithm for multiple value of k. And using the BIC score to find the best cluster configuration.

1

I recomend you to use Matlab in order to take your first steps on image processing. I've written a simple function that generates a pseudorandom image and then I will only take into account pixels with a value over a threshold value. The rest of the pixels will be set to zero. This is the code:

image=randi([0 255],10); %Used to generate a 10x10 image with pixel values between [0-255]

[row,col]=size(image); % to calculate the size of the image;
image_output=zeros([row,col]); %We make an empty image with the same size than the origial

TH_value=100; %threshold value 

index=find(image>TH_value); %searching for all the pixels with value>TH_value
n_idx=length(index); %number of pixels over TH_value

%no we have to replace in our empty new matrix only those pixels that have a value over the TH_value
for i=1:n_idx
    [row, col, ~ ] = ind2sub(size(image), index(i)); %geting the coordinates for all values over TH_value
    image_output(row,col)=image(row,col); %copying to the output matrix only the pixels over TH_value
end
image_output %in order to visualize the output image

Paste the code from above into Matlab to see how it works. It's pretty simple but it's ok as a start. Instead of generating a random image (see the first line of the code) you should import your own image using the "imread" function.

karl71
  • 1,082
  • 2
  • 18
  • 29