create mask (line) based on conditional (mask)
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
would like to create a mask that hightlights image pixels above or below a threshold
from each element in the mask, would like to draw a circle around it (anotehr mask) so as to make it stand out in the image
not sure how to implement the circular mask, seems to need XY coordinate (wont take maska)
function Findnoise(app, event)
highedit = str2num(app.highEditField.Value);
lowedit = str2num(app.lowEditField.Value);
maska= app.a >=highedit & app.a <=lowedit;
hcirc = drawcircle(app.UIAxes, 'Center',maska,'Radius',10,'StripeColor','red'); <- problematic line
% mask1 = hcirc.createMask;
% imagesc(app.a,'Parent',app.UIAxes);
end
0 commentaires
Réponse acceptée
DGM
le 20 Août 2024
Modifié(e) : DGM
le 20 Août 2024
You could do it using ROI objects, but that would be terribly slow and prone to other problems. Here's an example:
% dummy inputs
app.a = 0.06*randn(500,500);
imshow(app.a) % we need to display it to use the ROI tools this way.
app.highEditField.Value = '0.2';
app.lowEditField.Value = '0.8';
app.UIAxes = gca;
% create a logical mask
highedit = str2num(app.highEditField.Value);
lowedit = str2num(app.lowEditField.Value);
maska = app.a >= highedit & app.a <= lowedit;
% convert the mask to row,col subs
[y,x] = find(maska);
% draw a bazillion circle objects
maskc = false(size(maska));
for k = 1:nnz(maska)
hcirc = drawcircle(app.UIAxes, 'Center',[x(k) y(k)],'Radius',10,'StripeColor','red');
maskc = maskc | hcirc.createMask;
end
% show it
imshow(maskc)
It would make more sense to simply dilate the mask.
% dummy inputs
app.a = 0.06*randn(500,500);
app.highEditField.Value = '0.2';
app.lowEditField.Value = '0.8';
app.UIAxes = gca;
% create a logical mask
highedit = str2num(app.highEditField.Value);
lowedit = str2num(app.lowEditField.Value);
maska = app.a >= highedit & app.a <= lowedit;
% dilate the mask
maskc = imdilate(maska,strel('disk',10,0));
% show it
imshow(maskc)
The question seems to suggest that you were trying to create open circles, but I don't know what purpose that would serve as a mask. Either way, you can still do that.
% ... same setup as before
linew = 2;
% dilate the mask (hollow)
maskc = imdilate(maska,strel('disk',10,0)) ...
& ~imdilate(maska,strel('disk',10-linew,0));
% show it
imshow(maskc)
You could obviously then combine them if you wanted. The single pixels don't show up here on the forum, but they're there. As a visualization, this might be useful, but as a mask, I don't see a clear technical purpose.
% incorporate both masks?
maskcomp = maska | maskc;
% show it
imshow(maskcomp)
5 commentaires
DGM
le 22 Août 2024
There's no reason the threshold values or other parameters can't be controlled via some GUI, but I'm going to write conceptual demos that don't need a GUI. It's simpler that way, and it can run on the forum.
I don't know what your input image is, so I can only assume that if maskcomp is empty, then it's because maska is empty (i.e. nnz(maska) is zero). The strel you're using also only has a 1px radius, so it's not going to dilate very much. If your image is very large, or you're zoomed way out, small features simply may not display.
Plus de réponses (1)
Image Analyst
le 21 Août 2024
Based on your question and the answer, I don't understand. I don't know why you're messing with circles when regions in a threshold range will, in general, not be perfectly circular.
If you simply want to outline pixels above, or in the range of, a threshold, simply threshold and use bwboundaries followed by visboundaries.
If you want to tint different/separate regions with different colors and opacities, then use labeloverlay.
If you want a circle at the centroid of the blob just to "note" where the blob is in a visual sense, then you can use
hold on;
plot(x, y, 'r.', 'MarkerSize', 30);
to place a red dot at the centroid. To find the centroids you can use regionprops
props = regionprops(mask, 'Centroid');
xy = vertcat(props.Centroid);
x = xy(:, 1);
y = xy(:, 2);
You could also use the centroids to place a number at each centroid using the text function. This essentially counts/labels each blob with a unique number, rather than just doing a dot. Of course you could combine the things, like have the outline around each blob with a dot at the center and a number next to the dot.
If you want to place an ellipse over each blob (that has the same area as the blob and same orientation), see Steve's blog:
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!