Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Cannot understand the labeled region pixel value ..

1 回表示 (過去 30 日間)
Piyum Rangana
Piyum Rangana 2017 年 3 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Sonam Gupta
Sonam Gupta 2017 年 3 月 8 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by