How two fuse two sets of images?

조회 수: 3 (최근 30일)
Gabriele Ciccone
Gabriele Ciccone 2020년 3월 11일
댓글: Guillaume 2020년 3월 12일
Hi all,
I have two folders with same number of same dimnesion images : one for the greyscale images and one for the RGB images. I'm looking for a way to use imfuse (or a function like that) to combine image 1 from one folder to image 1 from the second folder, then image 2 from one folder to image 2 from the second folder, image 3 to image 3 etc etc..
edit: I'm looking for an aoutomatic way to do this for all the 230 + 230 images.
I'm an archaeologist so not really expert with code, but I learn fast!!
Thnaks a lot for any help!
  댓글 수: 4
Guillaume
Guillaume 2020년 3월 11일
You can do pretty much anything you want in matlab. The amount of effort can of course vary. As long as you have a rule for matching images from one set to the images of the other it should be easy. If it's just matching them in numerical order then it's easy.
Gabriele Ciccone
Gabriele Ciccone 2020년 3월 11일
Yes! I need to match them in numerical order. Do you have some suggestions or maybe a code the suits for my needs?
Thx!!

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

채택된 답변

Guillaume
Guillaume 2020년 3월 11일
Step 1: Download Stephen's natsortfiles.
Then adapt as needed. I still don't know what you want as output. I assume new images in another folder
folder1 = 'C:\somewhere\somefolder';
folder2 = 'C:\somewhere\someotherfolder';
folderout = 'C:\anothersomewhere\something';
outfilepattern = 'FancyName%03d.tif'; %see the documentation of sprintf for format string syntax
filelist1 = dir(fullfile(folder1, '*.tif'));
filelist2 = dir(fullfile(folder2, '*.tif'));
assert(numel(filelist1) == numel(filelist2), 'Mismatch between file count in input folders.');
filelist1 = natsortfiles({filelist1.name});
filelist2 = natsortfiles({filelist2.name});
for fidx = 1:numel(filelist1)
img1 = imread(fullfile(folder1, filelist1{fidx}));
img2 = imread(fullfile(folder2, filelist2{fidx}));
img_fuse = imfuse(img1, img2, 'montage'); %works even if one image is greyscale and the other is rgb. Smaller images get padded to fit the size of the larger one.
imwrite(img_fuse, fullfile(folderout, sprintf(outfilepattern, fidx)));
end
  댓글 수: 2
Gabriele Ciccone
Gabriele Ciccone 2020년 3월 12일
It works!
Thank you so much Guillame. I owe you!
Guillaume
Guillaume 2020년 3월 12일
If your problem is resolved, then please accept the answer that solved it.

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

추가 답변 (1개)

Ralf U.
Ralf U. 2020년 3월 11일
You can use the imfuse function to combine the images in the same plane. Have a look at the doc for more infos.
if you want to combine GRB and greyscale images, you might want to convert them both to RGB first:
rgbImage = cat(3, grayImage, grayImage, grayImage);
or if greyscale suffices:
rgbImage = ind2rgb(grayImage, colormap);
  댓글 수: 2
Gabriele Ciccone
Gabriele Ciccone 2020년 3월 11일
Yep, ok. But I need to combine 235 images from one folder to the 235 images of the other one: frist with first, second with second etc etc... I'm looking for an aoutomatic way to do this. Thx for any suggestion.
Guillaume
Guillaume 2020년 3월 11일
Note that imfuse will automatically convert a greyscale image to RGB if the other is RGB, no need to do this yourself.

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by