Changing amount of sharpen and smooth

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing amount of sharpen and smooth

dashko
Hi,
i am using ImageJ as library. And i am trying to change amount of sharpen, but i have no idea how to do it. This is how i can change sharpen and smooth

ImagePlus imp;
...
imp.getProcessor().sharpen();
imp.getProcessor().smooth();

Is there any function to change amount of sharpen? For example imp.getProcessor().sharpen(3.24)?

Please help.
Thanks a lot!
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

Gabriel Landini
On Sunday 11 April 2010, you wrote:
> Is there any function to change amount of sharpen? For example
> imp.getProcessor().sharpen(3.24)?

Not in the way you are trying to do it. Look at the source of ImageProcessor.
The method sharpen is a hard-wired 3x3 convolution kernel.

You will have to make your own kernel to sharpen more, or use a different
method (for instance the Process>Filters>Unsharp_Mask, command which supports
a radius and a weighting).

For smooth use the Gaussian blurring or the Mean filters which both support a
kernel radius.

G.
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

dashko
Ok, here is thing:
I have small image 275x275 pixels and i need sharpen this image. Then i have same picture, but larger 1600x1200 pixels, and i need apply exactly same sharpen (i applied on the small image).

That's a problem because i apply on small image, for example:

int[] kernel = {-1, -1, -1,
                -1, 30-amount, -1,
                -1, -1, -1};
imp.getProcessor().convolve3x3(kernel);

On larger image i can't use 3x3 kernel, it isn't same sharpen. I should use (275/3)/(1600/3) = 5 * 3 = 15, so convolve15x15 i guess :)

So is there any option in my case?
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

Michael Schmid
Hi Dashko,

probably the easiest would be to set the correct image scale (Analyze>Set
Scale) for both images and then use calibrated units for Gaussian Blur
(e.g., a radius of 1 micrometer for both). Set the pixel aspect ratio the
appropriate value if your pixels are not square, e.g. if you have
1200x1600 pixels but a square area.

For sharpening, it won't be so easy: you could subtract the image after
'Gaussian Blur' with the same radius in calibrated units. The result for
the two images won't be equivalent, however: With 1200 pixels, you will
have more details than with 275 pixels, so you would have to blur the
1600-pxl image first to show the same amount of detail as the 275-pixel
image.

Hope this helps,

Michael
________________________________________________________________________


On Sun, April 11, 2010 14:04, dashko wrote:

> Ok, here is thing:
> I have small image 275x275 pixels and i need sharpen this image. Then i
> have
> same picture, but larger 1600x1200 pixels, and i need apply exactly same
> sharpen (i applied on the small image).
>
> That's a problem because i apply on small image, for example:
>
> int[] kernel = {-1, -1, -1,
> -1, 30-amount, -1,
> -1, -1, -1};
> imp.getProcessor().convolve3x3(kernel);
>
> On larger image i can't use 3x3 kernel, it isn't same sharpen. I should
> use
> (275/3)/(1600/3) = 5 * 3 = 15, so convolve15x15 i guess :)
>
> So is there any option in my case?
>
> --
> View this message in context:
> http://n2.nabble.com/Changing-amount-of-sharpen-and-smooth-tp4884651p4885306.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

Gabriel Landini
In reply to this post by dashko
On Sunday 11 April 2010, you wrote:
> On larger image i can't use 3x3 kernel, it isn't same sharpen. I should use
> (275/3)/(1600/3) = 5 * 3 = 15, so convolve15x15 i guess :)
> So is there any option in my case?

I agree with Michael,  you can't do *strictly* what you want because the two
images have different data. Just scaling the kernel will not give you exactly
the same result as a smaller kernel on the smaller image unless you take into
relation how the small image was subsampled when reduced and so on.

The option in this case is to take a subimage of the original (no smaller,
just a subpart of it) and test the filters in that.
This way you have exactly the same filtering as you saw in the small image.

G.
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

dashko
Thanks for response. I think unsharp mask will be good compromise :)

But how can i apply Unsharp Mask. I tried
 IJ.run(imp, "Unsharp Mask...", "radius=3 mask=0.6");
But it returns Unrecognized command: Unsharp Mask...

And i tried:
UnsharpMask um = new UnsharpMask();
um.setup("radius=3 mask=0.6", imp);
ColorProcessor cp = (ColorProcessor) imp.getProcessor();
        cp.getHistogram();
        width = cp.getWidth();
        height = cp.getHeight();
        int[] pixels = (int[]) cp.getPixels();

FloatProcessor fp = new FloatProcessor(imp.getWidth(),imp.getHeight(), pixels);

fp.setSnapshotPixels(fp.getPixels());
um.sharpenFloat(fp, 3, (float)0.6);

bimg=fp.getBufferedImage();
imp = new ImagePlus("image", bimg);

But i can't cast or convert int[] to float[] pixels. How can i apply Unsharp Mask on my ImageProcessor?
Reply | Threaded
Open this post in threaded view
|

Re: Changing amount of sharpen and smooth

Michael Schmid
Hi Dashko,

your first version
    IJ.run(imp, "Unsharp Mask...", "radius=3 mask=0.6");
should work. Maybe you have mistyped the command or you have a hidden  
character in the string?
Does it work in a macro?
   run("Unsharp Mask...", "radius=3 mask=0.6");
If this does not work, your installation of ImageJ might be corrupted.

For an ImageProcessor ip of arbitrary type, I'd use something like  
the following:

    FloatProcessor fp = null;
    UnsharpMask us = new UnsharpMask();
    for (int i=0; i<ip.getNChannels(); i++) {
       fp = ip.toFloat(i, fp);
       fp.snapshot();
       us.sharpenFloat(fp, 3.0, (float)0.6);
       ip.setPixels(i, fp);
    }

For an RGB image, it loops over the R, G, B channels. For grayscale,  
the loop is executed only once. For a FloatProcessor, the ip.toFloat  
and p.setPixels only pass the reference to fp; no conversion is done.

Michael
________________________________________________________________

On 13 Apr 2010, at 16:06, dashko wrote:

> Thanks for response. I think unsharp mask will be good compromise :)
>
> But how can i apply Unsharp Mask. I tried
>  IJ.run(imp, "Unsharp Mask...", "radius=3 mask=0.6");
> But it returns Unrecognized command: Unsharp Mask...
>
> And i tried:
> UnsharpMask um = new UnsharpMask();
> um.setup("radius=3 mask=0.6", imp);
> ColorProcessor cp = (ColorProcessor) imp.getProcessor();
>         cp.getHistogram();
>         width = cp.getWidth();
>         height = cp.getHeight();
>         int[] pixels = (int[]) cp.getPixels();
>
> FloatProcessor fp = new FloatProcessor(imp.getWidth(),imp.getHeight(),
> pixels);
>
> fp.setSnapshotPixels(fp.getPixels());
> um.sharpenFloat(fp, 3, (float)0.6);
>
> bimg=fp.getBufferedImage();
> imp = new ImagePlus("image", bimg);
>
> But i can cast or convert int[] to float[] pixels. How can i apply  
> Unsharp
> Mask on my ImageProcessor?
> --
> View this message in context: http://n2.nabble.com/Changing-amount- 
> of-sharpen-and-smooth-tp4884651p4896256.html
> Sent from the ImageJ mailing list archive at Nabble.com.