필터 지우기
필터 지우기

Quickest way to join images preserving each colormap in MATLAB

조회 수: 7 (최근 30일)
carlos g
carlos g 2022년 7월 4일
편집: DGM 2022년 7월 8일
I am a having problem finding a way to join images preserving each colormap. I basically want to read images from a folder, place them in a rectangular grid (image11, image12; image21, image22) each with its own colormap. I have tried imtile() but I get black boxes at times and also for some reason the colormap is a greyscale instead of colours.
What would be the quickest way to do this? maybe forming a supermatrix containing all pixels of all images and then saving that as an image?
My pseudocode is simple:
for namefiles
im = imread(namefile);
imshow(im); %this works
out=imtile(im,'GridSize', [ypos xpos]); %this shows the pictures in black and white
imshow(out)
end
  댓글 수: 2
Jonas
Jonas 2022년 7월 4일
can you provide a sample set and can you show an image of your problem/error.
Are all images of same size, is the position only defined by the file name and which colormap do you want to use? or do you mean the colors as they should be when you use imshow() on them?
carlos g
carlos g 2022년 7월 4일
I am actually not convinced that imtile() is what I want, that's why I didn't provide my code, I have now added it. Yes, all images are the same size. I can provide the position in the "grid" by looping indices. Yes, the colours of imshow(im) are the right ones, the colors in imshow(out) are not (black and white for a reason that I don't know).

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2022년 7월 4일
편집: DGM 2022년 7월 4일
Read the images into a cell array in the loop. If the images are indexed color images, then convert them to RGB using ind2rgb() before storing them. Call imtile() or montage() on the cell array outside the loop.
nframes = 4;
C = cell(nframes,1);
for f = 1:nframes
[thisframe map] = imread(sprintf('pepframe%d.png',f));
if ~isempty(map)
thisframe = ind2rgb(thisframe,map);
end
C{f} = thisframe;
end
montage(C)
  댓글 수: 5
carlos g
carlos g 2022년 7월 8일
Thank you so much for all the detailed information. Unfortunately I now run into an 'Out of memory' error. My code is based on yours. How can I get around this?
for f = 1:length(files_array)
namefile=strcat(directory,strtrim(name_case_plot(sim_case,:)),'_vel1_',num2str(files_array(f)*10-1),'.png');
[thisframe map] = imread(namefile);
if ~isempty(map)
thisframe = ind2rgb(thisframe,map);
end
f
C{f,sim_case} = thisframe;
end
end
imtile(C','GridSize', [19 7])
DGM
DGM 2022년 7월 8일
편집: DGM 2022년 7월 8일
Ah. I didn't think about that. By default, ind2rgb() produces an array of class 'double'. You can reduce the memory requirements by a factor of 8 by doing:
C{f,sim_case} = im2uint8(thisframe);
If they still won't fit in memory, then the problem gets more complicated. There may have to be some compromises made. If there are further memory issues, it would be helpful to know how large the images actually are (height, width) and how much memory is available. That way I can at least estimate what might fit. If the images are all the same size, the requirements can be reduced by a factor of about 2.
The memory constraints would also mean that using mimread()/imstacker() from MIMT would be out of the question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by