How can I find all values that is over and under the iso-value and then visualize them?

1 view (last 30 days)
Trying some new things and wanted to do something like this
I've been trying for some time now but the closest i can get is the red circle. I figured I could use find() to find these values and then scatter() to visualize it. But I get errors that x and y is not the same length.
Here's the code:
x=linspace(-2,2,1000);
y=x';
z=exp(-(x.^2+y.^2));
a = find(z>0.2)
hold on
s = contour(x,y,z,[0.2 0.2], 'r')
scatter(z,a)

Answers (1)

Image Analyst
Image Analyst on 5 Oct 2022
Try this:
x=linspace(-2,2,1000);
y=x';
z=exp(-(x.^2+y.^2));
subplot(2, 1, 1);
imshow(z, []);
colorbar
% Find elements with z > 0.2
mask = z > 0.2;
% Overlay it on the image
subplot(2, 1, 2);
rgbImage = imoverlay(z, mask, 'r');
imshow(rgbImage);
% Get boundaries and display over the original image.
subplot(2, 1, 1);
hold on;
b = bwboundaries(mask);
visboundaries(b);
  2 Comments
Apo
Apo on 5 Oct 2022
Thank you but not what i was looking for, would like to have something similar to the pic.
Image Analyst
Image Analyst on 5 Oct 2022
But you have far too many points. You have a thousand x locations and a thousand y locations, so that's a million points. If you plotted them all as dots, they would be so close together that it would look essentially like an image. If you want far, far fewer points, like 30, you can do this:
x=linspace(-2,2,30);
y=x';
[X, Y] = meshgrid(x, y)
X = 30×30
-2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000 -2.0000 -1.8621 -1.7241 -1.5862 -1.4483 -1.3103 -1.1724 -1.0345 -0.8966 -0.7586 -0.6207 -0.4828 -0.3448 -0.2069 -0.0690 0.0690 0.2069 0.3448 0.4828 0.6207 0.7586 0.8966 1.0345 1.1724 1.3103 1.4483 1.5862 1.7241 1.8621 2.0000
Y = 30×30
-2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.8621 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.7241 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.5862 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.4483 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.3103 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.1724 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -1.0345 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.8966 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586 -0.7586
X = X(:); % Turn into a column vector.
Y = Y(:); % Turn into a column vector.
z=exp(-(X .^ 2 + Y .^ 2));
% subplot(2, 1, 1);
scatter(X, Y);
% colorbar
% Find elements with z > 0.2
Z = reshape(z, length(x), length(y))
Z = 30×30
0.0003 0.0006 0.0009 0.0015 0.0022 0.0033 0.0046 0.0063 0.0082 0.0103 0.0125 0.0145 0.0163 0.0175 0.0182 0.0182 0.0175 0.0163 0.0145 0.0125 0.0103 0.0082 0.0063 0.0046 0.0033 0.0022 0.0015 0.0009 0.0006 0.0003 0.0006 0.0010 0.0016 0.0025 0.0038 0.0056 0.0079 0.0107 0.0140 0.0175 0.0212 0.0247 0.0277 0.0299 0.0311 0.0311 0.0299 0.0277 0.0247 0.0212 0.0175 0.0140 0.0107 0.0079 0.0056 0.0038 0.0025 0.0016 0.0010 0.0006 0.0009 0.0016 0.0026 0.0041 0.0063 0.0092 0.0129 0.0175 0.0229 0.0288 0.0348 0.0405 0.0454 0.0490 0.0509 0.0509 0.0490 0.0454 0.0405 0.0348 0.0288 0.0229 0.0175 0.0129 0.0092 0.0063 0.0041 0.0026 0.0016 0.0009 0.0015 0.0025 0.0041 0.0065 0.0099 0.0145 0.0204 0.0277 0.0362 0.0454 0.0550 0.0640 0.0717 0.0774 0.0804 0.0804 0.0774 0.0717 0.0640 0.0550 0.0454 0.0362 0.0277 0.0204 0.0145 0.0099 0.0065 0.0041 0.0025 0.0015 0.0022 0.0038 0.0063 0.0099 0.0151 0.0220 0.0311 0.0421 0.0550 0.0690 0.0835 0.0972 0.1090 0.1176 0.1222 0.1222 0.1176 0.1090 0.0972 0.0835 0.0690 0.0550 0.0421 0.0311 0.0220 0.0151 0.0099 0.0063 0.0038 0.0022 0.0033 0.0056 0.0092 0.0145 0.0220 0.0323 0.0454 0.0616 0.0804 0.1010 0.1222 0.1423 0.1595 0.1721 0.1788 0.1788 0.1721 0.1595 0.1423 0.1222 0.1010 0.0804 0.0616 0.0454 0.0323 0.0220 0.0145 0.0092 0.0056 0.0033 0.0046 0.0079 0.0129 0.0204 0.0311 0.0454 0.0640 0.0868 0.1132 0.1423 0.1721 0.2004 0.2246 0.2424 0.2518 0.2518 0.2424 0.2246 0.2004 0.1721 0.1423 0.1132 0.0868 0.0640 0.0454 0.0311 0.0204 0.0129 0.0079 0.0046 0.0063 0.0107 0.0175 0.0277 0.0421 0.0616 0.0868 0.1176 0.1535 0.1929 0.2333 0.2717 0.3045 0.3286 0.3413 0.3413 0.3286 0.3045 0.2717 0.2333 0.1929 0.1535 0.1176 0.0868 0.0616 0.0421 0.0277 0.0175 0.0107 0.0063 0.0082 0.0140 0.0229 0.0362 0.0550 0.0804 0.1132 0.1535 0.2004 0.2518 0.3045 0.3546 0.3974 0.4289 0.4455 0.4455 0.4289 0.3974 0.3546 0.3045 0.2518 0.2004 0.1535 0.1132 0.0804 0.0550 0.0362 0.0229 0.0140 0.0082 0.0103 0.0175 0.0288 0.0454 0.0690 0.1010 0.1423 0.1929 0.2518 0.3163 0.3826 0.4455 0.4994 0.5389 0.5598 0.5598 0.5389 0.4994 0.4455 0.3826 0.3163 0.2518 0.1929 0.1423 0.1010 0.0690 0.0454 0.0288 0.0175 0.0103
mask = Z > 0.2;
% Overlay it on the image
hold on;
scatter(X(mask), Y(mask), 'r', 'filled');

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!