Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Cannot understand the labeled region pixel value ..

1 visualización (últimos 30 días)
Piyum Rangana
Piyum Rangana el 5 de Mzo. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi, According to the below code, I've labeled an image and by getting one label I take the pixel values out of it. The second output (That is as commented in the code itself) I cannot understand, that what kind of value it is. >> pixel (4, 29) the value is 452. Even though I analyse the pixel values of RGB channels I could not get any idea of the value. Could you please help me ?
im=imread('myImage');
im1=rgb2gray(im);
B=im2bw(im);
label=bwlabel(B);
max(max(label));
for j=5:5 %get the 5th label
[row, col] = find(label==j)
% 1st output
%row =
% 4
% 4
% 5
% 5
% 4
%col =
% 29
% 30
% 30
% 31
% 32
find(label==j) % 2nd output
%ans =
% 452
% 468
% 469
% 485
% 500
end

Respuestas (1)

Sonam Gupta
Sonam Gupta el 8 de Mzo. de 2017
The output in the second case is different because you are not explicitly assigning to [row col]. Instead it is like ans = find(label == j).
If we go through documentation for function 'find' at following link http://in.mathworks.com/help/matlab/ref/find.html , we will find that for the second case, find returns a vector containing linear indices of elements in label array that have value as j. 452 is the linear index for pixel(4,29) of the label array.
It is the position of the element when you count the elements column-wise. For instance, say you have an array A as below.
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Linear index for 14, i.e. pixel(4,2) will be 8 whereas for 10 , i.e. pixel (2,3) it is 10.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by