Outline the shape in the image

17 ビュー (過去 30 日間)
Hassan Strong
Hassan Strong 2020 年 5 月 31 日
コメント済み: Image Analyst 2021 年 8 月 31 日
Hi,
I need to outline a shape with circle in the image. Here is the image which i created using colormap.
The condition is if the 0.6<pixel<1 , then outline it with a circle. where pixel is the pixel value which is ranged from 0.1 to 1.
Here is the image info
Filename: XXXXX
FileModDate: '31-May-2020 23:43:42'
FileSize: 1588399
Format: 'tif'
FormatVersion: []
Width: 840
Height: 630
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: [1×70 double]
SamplesPerPixel: 3
RowsPerStrip: 9
StripByteCounts: [1×70 double]
XResolution: 96
YResolution: 96
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255]
MinSampleValue: [0 0 0]
Thresholding: 1
Offset: 1587608
ImageDescription: 'MATLAB Handle Graphics'

採用された回答

Image Analyst
Image Analyst 2020 年 6 月 1 日
You can use bwboundaries() and plot():
binaryImage = 0.6 < grayImage & grayImage < 1;
boundaries = bwboundaries(binaryImage);
hold on;
for k = 1 : length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:, 2); % Column
y = thisBoundary(:, 1); % Row
plot(x, y, 'r-', 'LineWidth', 2);
end
Attach your array or image file if you need more help.
  5 件のコメント
Alex Perrakis
Alex Perrakis 2021 年 8 月 31 日
Hey, is there a way to plot those lines in normal plot with x-y-coordinates? i have your solution and i have found very good success thanks
Image Analyst
Image Analyst 2021 年 8 月 31 日
@Alex Perrakis, yes, simply bring up a new axes - one that does not have an image it in already - and call the same code
binaryImage = 0.6 < grayImage & grayImage < 1;
boundaries = bwboundaries(binaryImage);
figure; % Create a new figure.
for k = 1 : length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:, 2); % Column
y = thisBoundary(:, 1); % Row
plot(x, y, 'r-', 'LineWidth', 2);
end
grid on;

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

その他の回答 (1 件)

Codeshadow
Codeshadow 2020 年 6 月 1 日
編集済み: Codeshadow 2020 年 6 月 1 日
You could try using contourf and specify the contour levels as an input argument.
For example:
% Create an example mesh
x = linspace(-1, 1, 100);
y = x;
[X, Y] = meshgrid(x, y);
% Compute the radii
R = sqrt(X.^2 + Y.^2);
% Generate contour map, with levels in increments of 0.1 or at a fixed value
% level = [0:0.1:1];
level = [0.6 0.6];
contourf(X, Y, R, level)
colorbar();
xlabel('X')
ylabel('Y');
Replace R used above with your data.
Note: You might not be placing a circle around your data, but will instead be tracing the isolines at the levels you desire.
Hope this helps!
  3 件のコメント
Codeshadow
Codeshadow 2020 年 6 月 1 日
Apologies, I'd made a typo in my original answer, and have fixed it now.
When specifying a single level in the contourf function, you will need to pass it in as a vector of two identical values, such as [0.6 0.6] in the corrected code above. If you want to plot several levels, you can specify all levels in a vector (see commented code).
For the example of the circle, if you specify a level as [0.6 0.6], you will get something like
You can use the Key-Value pair argument ('ShowText', 'on') to mark the levels if you'd like.
Hassan Strong
Hassan Strong 2020 年 6 月 1 日
Hi ,
Thank you very much

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

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by