How can I arrange images of splat over a 2D grid/matrix to form a 2D microstructure image?

5 ビュー (過去 30 日間)
Riddhiben Joshi
Riddhiben Joshi 2021 年 10 月 4 日
編集済み: DGM 2021 年 11 月 11 日
Hi everyone,
I have these 7 images of splats that have been simulated, out of which 4 are attched here. I am looking to arrange them randomly (in top view) over a two-dimensional grid/ matrix of 100um X 100um to create a 2D microstrutcre out of these images. I have tried a couple of fucntions like cat and montage but they dont seem to work the way I am expecting. It will be helpful if I can get some guidance on what function can help me create this microstructure grid.
Thank you!
  3 件のコメント
Riddhiben Joshi
Riddhiben Joshi 2021 年 10 月 4 日
編集済み: Riddhiben Joshi 2021 年 10 月 4 日
Hi, thank you for responding. I am looking to create a 2D image, which is there on the left of this image attached. The "Cat" fucntion just arranges image side by side for the splats.
Also, my images are not of same dimesions which could be reason for it not working.
DGM
DGM 2021 年 10 月 4 日
Ah okay. I think I see what you're after.

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

回答 (1 件)

DGM
DGM 2021 年 10 月 4 日
編集済み: DGM 2021 年 10 月 5 日
Here's a start. I imagine you may want to do other things (e.g. controlling spot size or randomizing it?). I'll leave those choices to you.
% i'm going to assume all the images have the same number of channels (3)
% also assuming images are uint8
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/758046/C_15.png');
B = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/758051/C_20.png');
C = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/758056/C_25.png');
D = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/758061/C_45.png');
imstack = {A; B; C; D};
numsources = numel(imstack);
maskstack = cellfun(@(x) x~=0,imstack,'uniform',false);
spotsizes = cell2mat(cellfun(@(x) [size(x,1) size(x,2)],imstack,'uniform',false));
numspots = 25; % number of spots
s = [1500 1500]; % output image size
bgcolor = [100 50 100];
padsize = ceil(max(spotsizes,[],1)/2);
outpict = ones([s(1:2)+padsize*2 3],'uint8').*permute(uint8(bgcolor),[1 3 2]);
sp = size(outpict);
for n = 1:numspots
sourceidx = randi([1 numsources],1,1);
rspot = spotsizes(sourceidx,:);
rxy = [randi([1 sp(1)-rspot(1)]) randi([1 sp(2)-rspot(2)])];
rangec = rxy(1):(rxy(1)+rspot(1)-1);
ranger = rxy(2):(rxy(2)+rspot(2)-1);
sample = outpict(rangec,ranger,:);
sample(maskstack{sourceidx}) = imstack{sourceidx}(maskstack{sourceidx});
outpict(rangec,ranger,:) = sample;
end
% get rid of padding
outpict = outpict(padsize(1)+1:padsize(1)+s(1),padsize(2)+1:padsize(2)+s(2),:);
imshow(outpict)
This example uses a simplified padding method based on the largest spot size. This does mean that some of the smaller blobs may lie entirely within the padding and be subsequently cropped off. The result is that the actual number of spots in the final image may be less than what's specified.
  4 件のコメント
Riddhiben Joshi
Riddhiben Joshi 2021 年 11 月 11 日
Hi thank you for your response. The distance between the splats is some what controlled by 4 equations A,B,C and D, where A and D equations are for circular disk shaped droplets, B and C are for more fragmented one. However i am trying to be able to have a parameter in code which can accept a value for dictance between codes. Can you please help me with this inclusion? Thank you.
DGM
DGM 2021 年 11 月 11 日
編集済み: DGM 2021 年 11 月 11 日
Well that's going to be a significant extra complication. Generating fields of points with spacing constraints is certainly doable, but I'm sure someone has better ideas about how to do it efficiently.
I don't remember if I asked, but is this distance the distance between spot centroids or the distance between spot edges? The latter would complicate things even more.
Assuming we're talking about distances between centroids, my initial idea would be to just build a list of points and discard those whose nearest-neighbor distance does not meet the chosen constraints. The rest would be an iterative process of adding random points and discarding invalid ones. Only after the point list is constructed would you start working on building the image.
If we're talking about distance between edges, then you wouldn't be able to simply build the point list first. I'm really not sure how I'd want to approach that. Maybe if you can approximate each spot type as having some equivalent radius, you could build your point list with a corresponding spot type list. That would give you another degree of freedom in the adjustment of invalid candidates. If a point were too close to its neighbor, you could swap its spot type for one with a smaller radius. If the irregular shape of the spots needs to be taken into account without approximating them as circles, then things are probably going to be slow.
In summary, I see three ways to abstract the problem description:
  1. Generate a field of points with constrained nearest-neighbor distances
  2. Generate a field of circles with constrained distances between edges
  3. Generate a field of irregular shapes with constrained distances between edges
Cases 1 and 2 would probably get traction if posed as a sufficiently abstracted fresh question. That would get more eyes on the topic. Case 3 isn't really abstracted enough to simplify the problem at all, so I don't know that a new question would help.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by