
Create the generated curve differently (function "bwboundaries")
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 14 de Dic. de 2022
Comentada: Image Analyst
el 17 de Dic. de 2022
Hi. I would like to be able to improve the following code so that:
1) the background always remains white and the curves always black (such as the .png figure);
2) the red curve that creates the code I would like it to become red but inside the black curve (see image obtained from the code)
3) I want to save all the coordinates ("boundary") that the code creates.

Below is the code:
baseFileName = 'image.png';
fullFileName = fullfile(pwd, baseFileName);
imag = imread(fullFileName);
figure();
imshow(imag);
%
imag_int8 = int8(imag);
BW = imbinarize(imag_int8);
%
[B,L] = bwboundaries(BW,'noholes');
figure
imshow(label2rgb(L, @jet, [0 0 0]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 5)
end
0 comentarios
Respuesta aceptada
Image Analyst
el 16 de Dic. de 2022
This works fine:
baseFileName = 'boundary.png';
fullFileName = fullfile(pwd, baseFileName);
binaryImage = imread(fullFileName); % It's already a logical binary image.
% Invert it so the black background is now the foreground.
binaryImage = ~binaryImage;
imshow(binaryImage); % Display it.
% Find boundaries.
[B,L] = bwboundaries(binaryImage,'noholes');
% Plot boundaries over image.
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r.-', 'LineWidth', 1, 'MarkerSize', 20)
end

Note, zoomed in, the pixels are like little squares and the coordinate is at the center of the pixel (center of the square block).
2 comentarios
Alberto Acri
el 17 de Dic. de 2022
Editada: Alberto Acri
el 17 de Dic. de 2022
Image Analyst
el 17 de Dic. de 2022
Not sure why you're ignoring my solution. Did you think it was no good so you decided to do it your own (wrong) way?
You're making the common beginner mistake of mixing up (x,y) with (row, column) (in addition to the mistake of ignoring my advice). bwboundaries returns (row, column) -- in other words (y, x) -- while plot needs (x, y).
Also, your "B" needs only 1 index, not 2, since there is just one cell for each boundary. There is no need for a second dimension even though what's inside the cell is a 2-D array.
Go back to the way I taught you and you'll be fine.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

