Overlay mask on to original image
18 ビュー (過去 30 日間)
古いコメントを表示
Hi - Coming to the end of writing a script to first segment particles and then save each individually. Ideally I would only like the particle pixels (without background in boundary box) so I am attempting to create masks of each particle, overlay this, make each binary ROI (value of 0) 'transparent' so that the particle is on show with white (value of 1) surroundings - I have tried modifying other similar examples on here but none of them seem to work and the saved image is just the cropped image mask or a big white box ... any advice would be greatly appreciated.
%I = original image
%binaryImage3 = logical mask created earlier on
folder = 'c:/Users/ezxjp1/Documents/MATLAB/ParticleImages'
for k = 1 : numberOfParticles
% Find the bounding box of each particle.
thisParticleBoundingBox = particleMeasurements(k).BoundingBox;
% Extract out this particle into it's own image.
subImage = imcrop(I, thisParticleBoundingBox);
% Create binary mask of subplot and overlay
subImageMask = imcrop(binaryImage3, thisParticleBoundingBox);
subImageMaskUnit8 = im2uint8(subImageMask);
% Get size of original image
[rowssubImage, colssubImage, numberOfColorChannelssubImage] = size(subImage);
[rowssubImageMaskUnit8, colssubImageMaskUnit8, numberOfColorChannelssubImageMaskUnit8] = size(subImageMaskUnit8);
% If size of mask does not match original, resize mask
if rowssubImageMaskUnit8 ~= rowssubImage || colssubImage ~= colssubImageMaskUnit8
subImageMaskUnit8 = imresize(subImageMaskUnit8, [rowssubImage colssubImage]);
end
Inew = subImage.*repmat(subImageMaskUnit8,[1,1,3]);
pngFileName = sprintf('Particle_%d.png', k);
fullFileName = fullfile(folder, pngFileName);
saveas(gcf, fullFileName);
end
1 件のコメント
Guillaume
2017 年 6 月 28 日
I'm not really clear what it is you're trying to do. Presumably, your particleMeasurements come from regionprops, isn't what you want the Image property returned by regionprops?
回答 (1 件)
Image Analyst
2017 年 6 月 28 日
I have no time to dig into your code yet, but here's a few quick links that might help with overlays:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!