How to select one image on montage and choose between the multiple images to select?

6 ビュー (過去 30 日間)
Friedman MAHARILAZA
Friedman MAHARILAZA 2018 年 4 月 16 日
編集済み: DGM 約13時間 前
Hello everyone! How to select one image on montage and choose between the multiple images to select, please?It's my problem now! Please send me the code to my email please. Thanks. friedman.maharilaza@gmail.com

回答 (1 件)

Elisa
Elisa 約21時間 前
A little late for the person posting the question, but I had the same question and when unable to find a good answer, I wrote a small function to suit me. I'm sharing it for others to benefit. See the attached m-file.
Notes:
Create your montage adding a *single* pixel black border to each:
montageImage = montage(catImages,'Bordersize',[1 1]);
Pass this image into the function:
imgNum = selectMontage(montageImage)
The function will display the montage image in a new figure.
You will be prompted to select the subimage of interest by clicking with the mouse (ginput).
The number the subimage is in the sequence that formed the montage will be returned.
  1 件のコメント
DGM
DGM 約14時間 前
編集済み: DGM 約13時間 前
This doesn't work as its described. As written, it will only work for single-channel raster images. It will not work directly on a composite RGB image, nor will it work directly on the output of montage() as the synopsis suggests. It also can't work if the images are separated by any more than two rows of black pixels.
% some images
a = imread('peppers.png');
b = imread('cameraman.tif');
% montage() accepts either a cell array of images or a monolithic 4D image
stack = {a b a b a b}; % a cell array
montageImage = montage(stack,'Bordersize',[1 1]); % montageImage is not a raster image
% since it's not a raster image, this doesn't work
imgNum = selectMontage(montageImage)
Error using sum
Invalid data type. First argument must be numeric or logical.

Error in selectMontage (line 26)
x_prof = sum(montageImage,1);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The output of montage() is a graphics object. Montage() is used to create and display a composite image, whereas imtile() simply creates a composite image and returns it as an output. If we already want to use montage() for display, we can just use montageImage.CData to get the underlying raster content.
As to the issues with RGB images and wider borders, these are one way of dealing with it:
% Sum rows and columns
x_prof = sum(montageImage,[1 3]); % fixes RGB issues
y_prof = sum(montageImage,[2 3]);
% Determine coordinates where borders exist
xx = find(x_prof==0);
xx = xx(1+find(diff(xx(:))>1)); % fixes wider border issues
yy = find(y_prof==0);
yy = yy(1+find(diff(yy(:))>1));
It might be best to ask where the images are coming from. If we're just dealing with arbitrarily preassembled composite images, we might have to deal with some sort of segmentation like this. Otherwise, if we are also doing the composition using montage() or simple concatenation, then we do have foreknowledge of the subimage geometry and the tiling order. From that, we can determine the image number based simply on the location within the composite image. We can also make sure that we don't produce an invalid output if we click on an empty spot in the montage (e.g. if we click the blank entry on a 2x3 montage containing fewer than six subimages)

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by