Figure to Image pixel conversions
조회 수: 3 (최근 30일)
이전 댓글 표시
If I plot a 100x100 matrix as a surface plot then save it as a jpg or png, then open the jpg/png, the pixel count is a lot different than the 100x100 values I had in the figure (or surface plot).
My question is how does matlab convert between the two (figure/surface plot to image)? I am assuming this probably has nothing to do with the original 100x100 matrix but instead the size of the figure (or surface plot) when it is saved as an image is what matters.
댓글 수: 1
Geoff Hayes
2020년 4월 29일
matthias - please include your code that shows how you are saving the plot (to file). If you are saving it as a figure, do you see the figure (menu, axes, etc.) in the jpg/png when you open it?
답변 (1개)
Vinai Datta Thatiparthi
2020년 5월 1일
Hello Matthias,
When you try to plot a [100 x 100] data into a surface plot (say, using the function surf), and then store it into an image format (say, .jpg), when you try to load this image into MATLAB again, you will not see the same data as the original [100 x 100] data that you tried to plot.
When you're plotting a surface plot, the values within the matrix correspond to the data that is plotted, but when you save it into an image, the pixel values do not correspond to the data points, but instead to other aspects of an image, such as the color (surface color when plotting with surf), axes, coordinates, etc. The .jpg image is stored as a UINT8 3D matrix. The values stored in these two (surface plot figure and the image) are simply not the same, and do not point to the same data in the first place.
If you want to get the same data, I suggest you store it in the form of a .mat file instead. That way, when you load the .mat file into your workspace again, you get the same exact values.
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!