User Defined Montage but filling 12x8 Array

2 views (last 30 days)
Jason
Jason on 19 Jan 2021
Answered: Rohit Pappu on 25 Mar 2021
Hello, I am scanning a sample that has a possible 12x8 locations. The user defines the positons to scan and the scan order is indicated by the number in the cells
I have a 1D cell array containing the images from the scan
imgArray{n}
I also have the row and col locations for each image
row=app.Positions(:,1) %column 1 for row locations
col=app.Positions(:,2) %column 2 for col locations
Whats the best way to create a montage splatting the images in the montage reflecting the positon in the table. For each image i have the row and col positons they were captured in. I would like to always display a 12x8 montage and just put positions where no image was created to e.g. blank (zero)
This was my attempt.
%First create "blank" images of zeros and position in all 12x8 locations
[sy,sx]=size(app.imgArray{1}) % Get size of each image, just used the 1st one as the size doesnt change
B=zeros(sy,sx); %Create a blank image
for j=1:8
for i=1:12
M(i,j)=B; %create a 12x8 array of blank images
end
end
Now positon the real images at their repsective locations
for i=1:m %m is the number of images
r=row(i); c=col(i);
M(r,c)=app.imgArray{i}
end
But I can't get passed creating the montage of blank images:
Error in HPBR/montage (line 1402)
M(i,j)=B;

Answers (1)

Rohit Pappu
Rohit Pappu on 25 Mar 2021
A possible workaround is as follows
% Create an empty cell array of size 12x8
imgList = cell(96);
% calculate the cell array position for each image based on
% it's row and column
pos = (row-1)*8 + col; % eg. 2nd row 3rd column image has a cell array position of (2-1)*8+3 =11
imgList{pos} = imgArray; % Store the images in a new cell array based on the position they should appear in imtile
imtile(imgList,'GridSize',[12 8]); % Create a 12x8 grid and place the images in the correct position

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!