• Post Reply Bookmark Topic Watch Topic
  • New Topic

Plugin in ImageJ giving random output, can't find reason.  RSS feed

 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to make a plugin for ImageJ a free photo editing program.
I need this plugin to make a mosaic of the original image. But instead it makes a random mosaic.
The problem lies somewhere in the avgList or calculation of this list. But I can't seem to find it.

Thank you very much in advance!
Here is my code:
Once without comments and one time with dutch comments.

Originally my code is commented but the comments are in dutch, if this is of any use for you, here it is:



 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you attach an image of what the output looks like, and -using that- describe what it *should* look like? Since the code uses Random, it's hard to know what is or is not desirable output.
 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Can you attach an image of what the output looks like, and -using that- describe what it *should* look like? Since the code uses Random, it's hard to know what is or is not desirable output.


Sure, the random() is used the generate random points inside the picture.
You start with this:


And you should get something like this, the output can change because you can change the amount of random points. Which changes the size of the tiles.


instead I get this:


Thanks!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, Lena :-)

I was able to reproduce output similar to what you got, but -not understanding Dutch- I'm at a loss to understand how the transformation should work. Should it create 500 even-colored blobs of somewhat equal but random size, each with a color based on the color that the original had at that location? Can you describe the algorithm words, and/or translate the comments?
 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tryed translating it in english and making a summary:

The image should look like its made with little tiles.
This should be achieved by:
- Calculating a series of random points, more points means smaller tiles.
- Assigning one of those random points to each pixel.
- A pixel is assigned to a random point when it is closest to that point.
- Than calculating the average value of all pixels for each random point.
- And giving each pixel the average value of all pixels closest to this one random point.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Sangster wrote:

This does not make a copy; it creates a new reference that points to the exact same object. As a result, when you modify "copyOfImage", you modify the same ImageProcessor object that "image" also points to. (Don't be ashamed, I made the same mistake when I started using OOP. And all the while I was wondering why my on-screen object kept growing all of a sudden... )

You'll need to create an actual copy. Fortunately, ImageProcessor has an easy way to do this - call the duplicate() method. So instead of calling you should call
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since "copyOfImage" is not actually used as an ImageProcessor, I declared it as "int[][] copyOfImage = new int[width][height]" (and trivially changed its use further down). For randoms=5000 I then got this image, which looks like what you might be after.

As an aside, if this kind of image manipulation appeals to you, my Pixellate plugin might also be to your liking.

lena_5000.jpg
[Thumbnail for lena_5000.jpg]
 
Tim Sangster
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you both VERY much for all the help although Rob's method doesn't seem to work for me, it still made me see my mistake!
And thank you Ulf for giving a solution! I'm now going to change so it works with rgb pictures which shouldn't be to hard.
After that I'll try to understand your Pixellate plugin.

Thanks again!
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!