Weird vertical artifacts appearing when saving images
조회 수: 6 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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()
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!