Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Cannot understand the labeled region pixel value ..

1 vue (au cours des 30 derniers jours)
Piyum Rangana
Piyum Rangana le 5 Mar 2017
Clôturé : MATLAB Answer Bot le 20 Août 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

Réponses (1)

Sonam Gupta
Sonam Gupta le 8 Mar 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by