How can I keep overlapping regions that I see in Imfuse and remove everything else in the image?

2 ビュー (過去 30 日間)
I used region props and have converted frames in a video binary images. How do I keep only the overlapping regions and remove everythign else? I would like to store the residual as frames to a video
  2 件のコメント
jonas
jonas 2020 年 7 月 6 日
Upload example images with your code?
AAS
AAS 2020 年 7 月 6 日
編集済み: Image Analyst 2020 年 7 月 6 日
The right most panel is the imfused image of the first and second panel. I would like to keep only the regions that have an overlap and discard everything else as shown in the next image i.e just keep the blue circled regions .

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

採用された回答

Image Analyst
Image Analyst 2020 年 7 月 6 日
This can be done in one line of code with imreconstruct().
J = imreconstruct(marker,mask) performs morphological reconstruction of the image marker under the image mask, and returns the reconstruction in J. The elements of marker must be less than or equal to the corresponding elements of mask. If the values in marker are greater than corresponding elements inmask, then imreconstruct clips the values to the mask level before starting the procedure.
  14 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 13 日
Sure. Just simply use pre in imreconstruct() instead of both:
% Initialization steps. Brute force cleanup of everything currently existing to start with a clean slate.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
pre = imread('pre.png');
post = imread('post.png');
% Convert to logical
pre = logical(pre(:,:,1));
post = logical(post(:,:,1));
% Show image.
subplot(3, 2, 1);
imshow(pre);
axis('on', 'image');
impixelinfo;
title('Pre', 'FontSize', fontSize);
% Show image.
subplot(3, 2, 2);
imshow(post);
axis('on', 'image');
impixelinfo;
title('post', 'FontSize', fontSize);
% Find common/overlap areas
overlapped = pre & post;
% Show image.
subplot(3, 2, 3);
imshow(overlapped);
axis('on', 'image');
impixelinfo;
title('overlapped', 'FontSize', fontSize);
fused = imfuse(pre,post,'falsecolor','Scaling','joint','ColorChannels',[1 2 0]);
subplot(3, 2, 4);
imshow(fused)
axis('on', 'image');
impixelinfo;
title('fused', 'FontSize', fontSize);
% Make output image.
output = imreconstruct(overlapped, pre);
% Show image.
subplot(3, 2, 6);
imshow(output);
axis('on', 'image');
impixelinfo;
title('Output', 'FontSize', fontSize);
AAS
AAS 2020 年 7 月 13 日
編集済み: AAS 2020 年 7 月 13 日
Thanks a ton! :D It worked beautifully

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by