Set exact Image size using imwrite
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a GUI (created with GUIDE) that has a fixed size. In this gui there is an axis element which is set by contourf. I have set this axis element by cursor to the pixel size of 720x480. I need exactly this size for the images I create via Imwrite. Now I have the problem that the images are generated partly correctly with the size 720x480, but also partly with less or more pixels (+-2). In the faulty images there is also a thin semi-transparent line at some edges (e.g. right or lower image edge). Depending on which data set or which axis scaling is used, this problem seems to occur or not (Before applying imwrite, I hide the X and Y axis by command: axes1.Y/XAxis.Visible = 'off').
What is the reason for this behavior and how can I fix it so that the images always have the same pixel size?
Many thanks in advance.
1 commentaire
Voss
le 8 Nov 2021
imwrite takes a matrix of data and writes it to an image file; the size of the image created by imwrite will be equal to the size of the data matrix you give it. Therefore, if (some of) your image files have the wrong size, it is because the data sent to imwrite did not have the intended size.
So the real question is, where does this data come from? For instance, if you program grabs image data from the GUI figure, like via print, and uses that in imwrite, then you should check that that data is the right size and your program may need to handle incorrectly-sized data at that point, maybe by padding or removing rows and/or columns.
Réponses (1)
Image Analyst
le 8 Nov 2021
If you're trying to get an "axis element" (like tick marks, or lines/graphics/annotations in the overlay), how are you doing it? If you're using getframe() then it returns basically a screenshot of the axes control and all its "elements". It will not usually be the identical size of the image contained in the axes control. If you want the image part of the thing you got from getframe() to have the same size as the image you'll have to figure out what size the image is in that screenshot and resize that screenshot image such that the image in it is the same size as the image in the axes control.
Also the axes control is the size of the control. If you set the 'Position' property of that to make it some exact size, be aware that that included everything in the axes including the graph or image, and space for tickmarks and labels and white space padding. It's not the size of just the stuff inside the graph box.
2 commentaires
Image Analyst
le 9 Nov 2021
@Runz Reiner somehow you're going to have to use the output arguments C and h to burn them into the image, then use imwrite. One thing you might try first is to see if you call getimage() instead of getframe(), does that return the image that is the same size as the one you displayed. If not, use imresize() on it, possibly with the 'nearest' option so it doesn't get blurred.
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!