Weird vertical artifacts appearing when saving images

조회 수: 6 (최근 30일)
Stephen Skapek
Stephen Skapek 2022년 5월 4일
답변: Walter Roberson 2022년 5월 4일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2022년 5월 4일
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()

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by