Skip to content

Scaling and Artifact Problem in colorview #204

Open
@johnnychen94

Description

@johnnychen94

Manually transfered from JuliaImages/Images.jl#882. The following contents are originally posted by @roflmaostc. This seems only an ImageMagick issue, using PNGFiles/ImageIO work arounds it.


Hey,

I observed a bug for which I didn't find an explanation so far. I wrote a Poisson noise function which adds noise to the image. If I inspect the final images with imshow, all seems to be fine.

However, only for the parameter value nphot=3, nphot=5 and nphot=15, if I save the image (or inspect them directly with colorview) these images are scaled and shifted to the left. On the right part, there are some artifacts

I cropped the images so that only intensities between 0 and 1 are possible.

Not working: nphot=3, nphot=5, nphot=15

One working example: nphot=10

Here is the full code example:

using Images, TestImages, PoissonRandom, ImageView

function my_poisson(img; nphot=100)
    nphot = float(nphot)
    max_intens = maximum(img)
    #scale image to maximum number of photons and apply poisson noise
    img_noisy = map(x -> pois_rand(x / max_intens * nphot), img)
    #rescale to initial intensity
    img_noisy = img_noisy ./ nphot .* max_intens

    #crop intensity
    img_noisy = map(x -> max(0.0, x), img_noisy)
    img_noisy = map(x -> min(1.0, x), img_noisy)

    return img_noisy
end


img = testimage("cameraman")

#i=3, i=5 and i=15 cause strange output
for i=1:15
    img_poiss = my_poisson(img, nphot=i)
    img_poiss_view = colorview(Gray, img_poiss)
    save(string("test", i, ".png"), img_poiss_view)
end

#this part works totally fine
img_poiss = my_poisson(img, nphot=15)
img_poiss_view = colorview(Gray, img_poiss)

imshow(img_poiss_view)

Edit: with different image size, the parameter, where the result is weird, changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions