필터 지우기
필터 지우기

Outline the shape in the image

조회 수: 21 (최근 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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by