Weird vertical artifacts appearing when saving images

6 views (last 30 days)
So I'm trying to make some visualiztions of various strange attractors. The code creates a 4000x4000 mesh over a planar interval, simulates 1000000 iterations of a particle moving, counts the number of times the particle ends up in a particular grid space, and then assigns a scaled numerical value to a corresponding entry in a 4000x4000 double array. MATLAB has no issues rendering the array as an image with this code.
image(MeshCount,'CDataMapping','scaled');
colormap('turbo');
This is a screenshot of what is rendering in my figure window.
The issue arises when I attempt to process and save natively from MATLAB.
output = normalize(MeshCount,'range',[0,60])
imwrite(output, turbo(60), 'output.jpg')
As you can see, it's suddenly developed these vertical lines when attempting to render. Using a different colormap, changing what type of file is being saved, or even messing around with the datatype of MeshCount does nothing. I assume there's something going on with how normalize handles the array, but I thought it just term by term passed through everything to linearly scale all values into the indicated range. Does anyone have some insight into what is happening here?

Answers (1)

Walter Roberson
Walter Roberson on 4 May 2022
normalize() with range 0 to 60 produces double precision output in the range 0 to 60.
When you imwrite double precision then the assumption is that the input is in the range 0 to 1 with values outside the range to be clamped.
I suggest that you use rescale() instead of normalize()

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!