Montage of two Images

5 次查看(过去 30 天)
Hello Everyone, I have a code that finds an image from a path. That image is then cropped. The Cropped image is then converted into a Binary Image, I would like to stitch these pictures together as one figure. I tried using Montage. I however recieve errors using Montage. here is my code :
filePattern = fullfile(myFolder, '*.tif');
imageFiles = dir(filePattern);
for k = 1:length(imageFiles)
ImagebaseFileName = imageFiles(k).name; %image name
image_original = fullfile(myFolder, ImagebaseFileName); %original image
%fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(image_original);
image_cropped=imcrop(imageArray, [0 0 632 1024]); %Cropping Image
%%Binary Gradient Mask
[~, threshold] = edge(image_cropped, 'sobel');%Binary Gradient Mask
fudgeFactor = .5;
image_bin_grad_mask = edge(image_cropped,'sobel', threshold * fudgeFactor); % Binary Gradient Mask Image
montage(image_bin_grad_mask,image_cropped); % Display image.
end
Also I would like to store the created montage as a seperate image.Any suggestions. Your help, effort and time are much appreciated.
Best Regards

采纳的回答

Nut
Nut 2017-5-18
Hi,
if you need only to display the two images side by side you can use subplot.
Instead, if you need to join the two images together into a unique one, I think the cat function may be helpful for you:
https://it.mathworks.com/help/matlab/ref/cat.html
  3 个评论
Sreejoe Kaniyamparambil
Okay, found the mistake, the original image wasn't a logical image. I converted the 2 gradient images to uint8 images, using im2unit8. Thank you so much for your help!!!
Nut
Nut 2017-5-18
编辑:Nut 2017-5-18
You're welcome, I'm glad it works for you. Thanks for accepting my answer, kind regards.

请先登录,再进行评论。

更多回答(2 个)

Rik
Rik 2017-5-18
Montage is rather picky about the image format. It wants the following input format: (rows,columns,colors,pages). What you tried to do is therefor impossible with montage. If your goal is to show the two images side by side, you can use the subplot functionality.
subplot(2,1,1)%(total_rows,total_cols,current_index)
imshow(image_bin_grad_mask)
title('Original image')
subplot(2,1,2)
imshow(image_cropped)
title('Cropped image')
  2 个评论
Sreejoe Kaniyamparambil
Hi, thank you very much for your answer. I tried it using subplot alread. I would however for comparison purposes like to have a 'stitched image'. Which is why I opted against subplot/subimage. You said montage is rather picky, all my images are from one Video file ( each frame was stored as an Image). Meaning they all have the same size, the same number of rows and columns etc., what would be the correct way to montage the images? Regards
Joe
Rik
Rik 2017-5-18
You said in your question you wanted to put both a cropped image and the original in one frame. That means you have unequal image sizes.
If you want to make a montage of a video file, you need to make sure that the 3rd dimension is the color dimension and the forth dimension is the different frames. If you have those two switched around, you can use permute to change the order.
montage_friendly_format=permute(video,[1 2 4 3]);

请先登录,再进行评论。


Hannan Awan
Hannan Awan 2020-10-17
use figure; before using montage command.

Community Treasure Hunt

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

Start Hunting!

Translated by