Hi,

I have a project where we need to scan each pixel from an image. Somewhere in the image there will be a 10x10 red pixel and we need to draw a circle around it. This is the code I have so far: (but I'm having trouble figureing out the code to scan each pixel?) Any help would be great! Thanks

``````public static void main(String[] args) {

TheMatrix picture = new TheMatrix(EasyInput.openFileDialog());
int width = picture.getWidth();
int height = picture.getHeight();
int[] pixels;
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color c = picture.getColor(x, y);
if (c == Color.RED){
for (int x = 0; x < 199; ++x) {
int y = (int) (Math.sqrt(200 * 200 - x * x));
picture.setColor(250 + x, 250 + y, Color.WHITE);
picture.setColor(250 - x, 250 + y, Color.WHITE);
picture.setColor(250 + x, 250 - y, Color.WHITE);
picture.setColor(250 - x, 250 - y, Color.WHITE);
picture.show();
}
``````

Paula

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
4
Views
13 Years
Discussion Span
Last Post by server_crash

i don't quite understand your question and your program, but i understand this :
these is a 10 pixel x 10 pixel sized red square in a picture, we need to find it and draw a circle around it.
well we can solved like this, we need an 10x10 array which will hold the color values... also we need another 2d array which is for the circle, for example a 15x15, we need to fill this array only for once at the beginning.
we start to get every 10x10 from the picture and check if all of the values are RED. then when we found red square we put the circle-array over the red square...
that is the algorithm i found...
i hope i understand correctly.

I think there is some method that takes an image, and creates an array of pixels out of it:

I think it's something like this:

``int x = getPixels(Image);``
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.