Borrar filtros
Borrar filtros

loading images without compression

6 visualizaciones (últimos 30 días)
Thijs Boeree
Thijs Boeree el 12 de Nov. de 2023
Comentada: DGM el 21 de Nov. de 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 comentarios
Matt J
Matt J el 12 de Nov. de 2023
Editada: Matt J el 12 de Nov. de 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 el 12 de Nov. de 2023
Editada: DGM el 12 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Nov. de 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 comentarios
Thijs Boeree
Thijs Boeree el 19 de Nov. de 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 el 21 de Nov. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by