Create composite mask, and apply this mask to an image
4 ビュー (過去 30 日間)
古いコメントを表示
Shane Browne
2020 年 11 月 29 日
コメント済み: Tarunbir Gambhir
2020 年 12 月 4 日
Hi,
Scanning samples using NIR, processing the spectra in matlab.
I have an image, and I need to create a mask to remove the background.
I have been instructed to snip sections of the image, creating masks.
I then have to combine these masks (x3) into one composite and apply it to the overall image. Removing the background.
CL below is a crop of image I5.
CL=I5(131:149,36:43,:);
[xC,yC,zC]=size(CL);
figure,imshow(mean(CL,3),[])
I searched through a loop showing each slice of the hypercube. Slice for example 69 has contrast between the item and the background.
The threshold excludes the background.
%%CL snip one
figure,
subplot(1,2,1),imshow(CL(:,:,69)<0.26,[])
subplot(1,2,2),histogram(unfold(CL(:,:,69)),100)
CL_mask=CL(:,:,69)<0.26;
%% CL3 my second crop of the image
CL3=I5(125:150, 15:34,:);
[xC3,yC3,zC3]=size(CL3);
figure,imshow(mean(CL3,3),[])
CL_mask3=CL3(:,:,81)<0.1;
%% CL4 snip four
CL4=I5(153:168,25:41,:);
[xC4,yC4,zC4]=size(CL4);
figure,imshow(mean(CL4,3),[])
CL_mask4=CL4(:,:,65)<0.24;
Is there a way to combine the three masks? CL_mask4 + CLmask3 + CL_mask ?
I am a beginner level user, but I can provide more info if it helps.
Help would be hugely appreciated.
Shane
0 件のコメント
採用された回答
Tarunbir Gambhir
2020 年 12 月 2 日
A better approach would be to use a single mask for your entire image. Start with a matrix of same size as your image and update it at locations where the threshold condition suffices inside the cropped regions.
Something like this could be done:
% Assuming the dimensions of image to be Spacial x Spacial x Spectral
mask = zeros(size(I5,[1,2])); % Initialize mask with zero across spacial dimensions
%% CL
mask(131:149,36:43)=I5(131:149,36:43,69)<0.26;
%% CL3
mask(125:150,15:34)=I5(125:150,15:34,81)<0.1;
%% CL4
mask(153:168,25:41)=I5(153:168,25:41,65)<0.24;
Repeating the mask value across all spectral slices and then dot-multiplication with the original image should give you the masked image.
%% Applying the mask to I5
final_image = I5 .* repmat(mask,[1 1 size(I5,3)]);
2 件のコメント
Tarunbir Gambhir
2020 年 12 月 4 日
Yes. After getting the mask you could use a "for" loop in this way to check if the mask worked for every slice.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!