There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Marshall,
one way would be to get the coordinates of a point (pixel)
of which you are certain it is part of the eye that needs
to be changed.
Let the color of that point be C, and let the wanted color be W
Now, create a Queue<Point> (a LinkedList is fine!) and
put that point on the queue.
Now, while the Queue is not empty:
retrieve the head
change the corresponding pixel to W (see your libray for a suitable method!)
get its four neighbors
for each neighbor: if the color of the corresponding pixel is C, put it on the queue.
I.e: we do a floodfill with color W, to non-C, in the terms of my old BASIC.
There are three kinds of actuaries: those who can count, and those who can't.
Marshall Mathers wrote:To be honest with you, I was not taught how to create linked lists or any of the storage methods yet...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Hmm, I'm not sure what is unclear about the 'what'.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:We're dealing with rasterized images, not vectorized images.
In OP's previous topic, I gave a link to the library he's using.
You can see what methods are available.
But let's wait for a reaction of OP, to see where we are now.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Marshall,
the error is due to the fact that the method 'floodfill' is not part of the Picture class.
We could make it part of a new class that extends 'Picture', but I'm afraid that
we would be far ahead of the course you are doing (nd which I wasn't aware of).
So that makes that you and I should be very careful in the methods and algorithms.
Do you think the use of a LinkedList is allowed? In my view, Collections would be a
subject I would treat before I would start touching on Pictures and Pixels.
But anyway: in your code you do:
As explained, the 'Picture' class does not contain e method 'floodfill'.
To use this method, you must invoke:
Remarks:
1) so you need some pixel to start from. Well, if I look at the image
you provided in your opening post, it is very easy to determine a starting pixel.
Just put the mouse over one of the pixels-to-change, and you can read its
x- and y value.
2) in the floodfill-method, I assumed that if I have a pixel from a picture
(for instance)
that changing the color of that pixel, also implies that the picture itself
is updated. However, that may not be the case, so you might have
to look at a method in the 'Picture' class that lets you update the color of
a pixel.
3) as you can see, if you want to change other parts of your picture, then you
need other 'starting pixels'. So, in the same manner, find other pixels that are in
an area that you might want to change as well. The floodfill method is a general
method in that sense.
4) but again: I do not have this library, and I do not know what you have
been given so far in this course. So, I am unable to test code, and furthermore,
it is up to you to apply all that has been taught to you. If you are not allowed
to use a LinkedList, then what other ways do you know that can handle
the data?
5) so: work to do! try to get the 'floodfill' method working. Correct
all the things that are wrong with it. A very good idea is to call this
'floodfill' only when the uer clicks on the image. That will give you
your 'starting pixel' for free!
6) and finally (but least important): the floodfill method as it is now,
is not very efficient!
It can be made much more efficient quite easily, but not for now.
Marshall Mathers wrote:I think that I am allowed to use a linked list as long as I can explain what it does. I've been taught how to use them about a year ago so that's not a problem. The problem is that I don't know how to use them in terms of Java.
Also, the only error I seem to get now (which is probably a very stupid one) is the fact that '-120' is highlighted red...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Marshall,
thanks for the jar file. I finally could make a demo that I could test.
Here it is. . . .
Marshall Mathers wrote:So, I was thinking and is there a way to create something MUCH simpler that would more or less do what this pseudo code below does?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Marshall Mathers wrote:So, I was thinking and is there a way to create something MUCH simpler that would more or less do what this pseudo code below does?
I suspect so, but I'll let Piet guide you.
The only thing I would say is that you need to define that Step 3 ("IF the colour = original colour in that set area THEN change colour to new colour") a bit more clearly.
Do you want to change the colour only when ALL pixels in your rectangle are the original colour, or do you want to change (eg) each BLUE pixel in the area to a RED one?
Winston
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:...
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:@Winston: You wrote you had a suggestion. Can you tell us what you have in mind?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Piet Souris wrote:@Winston: You wrote you had a suggestion. Can you tell us what you have in mind?
Erm...not sure. Can you remind me where?
There are three kinds of actuaries: those who can count, and those who can't.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |