Effacer les filtres
Effacer les filtres

loading images without compression

6 vues (au cours des 30 derniers jours)
Thijs Boeree
Thijs Boeree le 12 Nov 2023
Commenté : DGM le 21 Nov 2023
Hello there,
I've made a for loop for filling a struct with png images, this because i need to recall the same images a view times in my application. If i recall my images from the struct i get the images but there seems to be a jpg compression on the png file? This is how i load the struct:
imageDir = 'Edwin\files\'; % Map met de afbeeldingen
imageExt = '.png'; % Extensie van de afbeeldingen
% Lijst van afbeeldingsnamen zonder extensie
imageNames = {'edammer', 'edammer_selected', 'emmentaler', 'emmentaler_selected', 'beemster', 'beemster_selected', ...
'gorgonzola', 'gorgonzola_selected', 'goudse', 'goudse_selected', 'gruyere', 'gruyere_selected', 'manchego', ...
'manchego_selected', 'noordwoudse', 'noordwoudse_selected', 'roquefort', 'roquefort_selected', ...
'kaasfondue3','kaasfondue4','kaasfondue5','kaasfondue6','kaasfondue7','kaasfondue8','kaasfondue9', ...
'edammer_vlag', 'edammer_vlag_selected', 'gorgonzola_vlag', 'gorgonzola_vlag_selected', 'manchego_vlag', ...
'manchego_vlag_selected', 'roquefort_vlag', 'roquefort_vlag_selected', 'haarlem_vlag', 'haarlem_vlag_selected', ...
'basel_vlag', 'basel_vlag_selected', 'gruyere_vlag', 'gruyere_vlag_selected', 'goudse_vlag', 'goudse_vlag_selected', ...
'emmentaler_vlag', 'emmentaler_vlag_selected', 'kaasfondue33','kaasfondue34','kaasfondue35','kaasfondue36','erik0','erik1', ...
'erik2','erik3','erik4','erik5','erik6','erik7'};
% Loop door de lijst van afbeeldingsnamen en laad de afbeeldingen
for i = 1:length(imageNames)
imageName = imageNames{i};
imagePath = [imageDir, imageName, imageExt];
app.imageStruct.(imageName) = imread(imagePath,"png", 'BackgroundColor', [0.94 0.94 0.94]);
end
imageStructfile = app.imageStruct;
save("Edwin\files\imageStruct.mat",'imageStructfile');
And when i load an image from the struct it looks like this:
app.image_Erik.ImageSource = app.imageStruct.erik0;
Can anyone tell me if i am doing something wrong.
If i load the image with app.image_Erik.ImageSource = imread('files/erik0.png'); then i don't see any compression...
Best regards,
Thijs
  2 commentaires
Matt J
Matt J le 12 Nov 2023
Modifié(e) : Matt J le 12 Nov 2023
there seems to be a jpg compression on the png file?
Please show the indications of that to us. Ideally, you would run your code here online so we can see the result.
DGM
DGM le 12 Nov 2023
Modifié(e) : DGM le 12 Nov 2023
It may also help to know how the images were created. For example, if they're color photographs, then chances are that they were JPG to begin with.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 12 Nov 2023
app.imageStruct.(imageName) = imread(imagePath,"png", 'BackgroundColor', [0.94 0.94 0.94]);
The fact that you are specifying the backgroundcolor tells us that your png images are not rgb images. They are probably indexed images -- and you are failing to read and apply the colormap.
  29 commentaires
Thijs Boeree
Thijs Boeree le 19 Nov 2023
I have an app with a possibility to select and deselect several (27) images. I use the same images more than once, for the sake of speed i wanted to put all the images in a struct (memory) and then load and change (unload and load) within the app. Now the app has to read the image every time from the hard drive.
DGM
DGM le 21 Nov 2023
That's basically the gist of it. Needing to rely upon direct file reads makes uiimage() significantly less practical in my opinion. I've filed a bug report, but that doesn't really fix things for current needs.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by