loading images without compression

8 次查看(过去 30 天)
Thijs Boeree
Thijs Boeree 2023-11-12
评论: DGM 2023-11-21
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 个评论
Matt J
Matt J 2023-11-12
编辑:Matt J 2023-11-12
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 2023-11-12
编辑:DGM 2023-11-12
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-11-12
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 个评论
Thijs Boeree
Thijs Boeree 2023-11-19
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 2023-11-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by