Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
The image is scaled color version of absolute value of the matrix.

Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Aug. 2018
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 Kommentare
Image Analyst
Image Analyst am 29 Aug. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Community Treasure Hunt

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

Start Hunting!

Translated by