Outline the shape in the image
Show older comments
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'
Accepted Answer
More Answers (1)
Codeshadow
on 1 Jun 2020
Edited: Codeshadow
on 1 Jun 2020
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 Comments
Hassan Strong
on 1 Jun 2020
Codeshadow
on 1 Jun 2020
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
on 1 Jun 2020
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

