Given an image , how to efficiently (vectorization) make all the elements to zero except the one with information?

1 回表示 (過去 30 日間)
The image is scaled color version of absolute value of the matrix.

採用された回答

Image Analyst
Image Analyst 2018 年 8 月 28 日
This will do it:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;fontSize = 22;
s = load('image_data.mat')
D = s.D;
realD = abs(real(D));
imagD = abs(imag(D));
subplot(2, 3, 1);
imshow(realD, []);
axis square
title('Real Image', 'FontSize', fontSize);
impixelinfo();
subplot(2, 3, 2);
histogram(realD);
grid on;
title('Histogram of Real Image', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(imagD, []);
axis square
title('Imaginary Image', 'FontSize', fontSize);
impixelinfo();
subplot(2, 3, 5);
histogram(imagD);
grid on;
title('Histogram of Imaginary Image', 'FontSize', fontSize);
backgroundValueR = 5e8;
backgroundValueI = 3e8;
binaryImageR = realD > backgroundValueR;
binaryImageI = imagD > backgroundValueI;
subplot(2, 3, 3);
imshow(binaryImageR, []);
axis square
impixelinfo();
title('Real Image, binarized', 'FontSize', fontSize);
subplot(2, 3, 6);
imshow(binaryImageI, []);
axis square
impixelinfo();
title('Imaginary Image, binarized', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Apply the mask
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRealImage = bsxfun(@times, realD, cast(binaryImageR, 'like', realD));
maskedImagImage = bsxfun(@times, imagD, cast(binaryImageI, 'like', imagD));
figure;
subplot(2, 1, 1);
imshow(maskedRealImage, []);
axis square
impixelinfo();
title('Masked Real Image, binarized', 'FontSize', fontSize);
subplot(2, 1, 2);
imshow(maskedImagImage, []);
axis square
impixelinfo();
title('Masked Imaginary Image, binarized', 'FontSize', fontSize);
  9 件のコメント
Image Analyst
Image Analyst 2018 年 8 月 29 日
I gave two comments above telling you how to do that. You inspect the histogram. It's a judgement call - there are lots of values you could use so just decide where in the histogram you want to threshold it.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 8 月 26 日
Probably thresholding and masking.
mask = theImage ~= backgroundValue; % Threshold.
theImage(mask) = 0; % Mask
Attach your data in a .mat file if you want more help.

カテゴリ

Help Center および File ExchangeWhite についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by