Combine pixels into regions

1 visualización (últimos 30 días)
Valeriya Gmyria
Valeriya Gmyria el 9 de Oct. de 2021
Comentada: Valeriya Gmyria el 12 de Oct. de 2021
Hello everyone! There is such a task.
There is an image in which, after processing, the background has brightness = 0, objects have non-zero brightness. It need to combine these objects on the region and assign them an ID. The idea is this: the algorithm scans the image line by line, if it detects a non-zero pixel, stores its coordinates and the intensity(brightness) and starts checking neighboring pixels. If it detects non-zero ones among the neighbors, then it also stores their coordinates and intensity. Later these values ​​will be needed for calculations. When the first region is selected in this way, intensity = 0 should be assigned to all pixels included in it. After that, the algorithm continues to scan the image line by line in search of non-zero pixels and, if found, repeats the above steps. So far, I have it:
img = imread('t.png');
[x, y] = size(img);
for i = 1:x
for j = 1:y
if img(i,j) ~= 0
%store coordinates and brightness
if img(i, j+1) ~= 0%%check right neighbor pixel
% store coordinates and brightness
j = j + 1;
end
if img(i+1, j) ~= 0%%check lower neighbor pixel
% store coordinates and brightness
i = i + 1;
end
end
end
end

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Oct. de 2021
Is this homework, where they asked you to write your own version of bwlabel() or bwconncomp? Otherwise, why not simply use one of those functions?
  3 comentarios
Image Analyst
Image Analyst el 11 de Oct. de 2021
You're welcom, but what does that mean? Are you saying you just used bwlabel (like I suggested) instead of trying to rewrite it yourself? If so, can you please "Accept this answer"?
Valeriya Gmyria
Valeriya Gmyria el 12 de Oct. de 2021
I'm used bwlabel.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by