필터 지우기
필터 지우기

loading images without compression

조회 수: 6 (최근 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