Problem when changing labels in image
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello
I have a strange problem with labeling an image in MATLAB. I do not know if this is a problem occurring by my mistake or is caused by MATLAB.
I have a cell matrix with string names containing the classes (classification) of image objects called MK
The number of labels in the image is equal to Num
My label image is called LL
The problem occurring is that when I loop through the image and try to change the labels some of the objects within are lost. I do not know why this is happening. The labels within the image have a range from 1 to 8 (in this case) and the MK vector contains 8 class names.
My code look like this
for i=1:Num
ccc=MK(i);
% Convert to character
cc=char(ccc);
if strcmp(cc,'Water')
LL(LL==i)=100;
end
if strcmp(cc,'Soil')
LL(LL==i)=200;
end
if strcmp(cc,'Trees')
LL(LL==i)=300;
end
if strcmp(cc,'Vegetation')
LL(LL==i)=400;
end
if strcmp(cc,'Building')
LL(LL==i)=500;
end
if strcmp(cc,'Shadow')
LL(LL==i)=600;
end
end
I would really appreciate some help with this problem as I am stuck and I can not find a solution !
댓글 수: 0
채택된 답변
Image Analyst
2012년 7월 13일
편집: Image Analyst
2012년 7월 13일
Tell me what this says
max(LL(:))
You say it's supposed to work with any number of objects but you're going to have a problem with your code if you have more than 100 objects because you will be replacing their labels with your new ones. And tell me why you think some of the labels are lost. What does
numberOfObjects = hist(LL(:))
return?
And why do you want the labels to be a multiple of 100 in the first place? That is not necessary for anything as far as I can tell.
By the way, you could get rid of the loop entirely with a single call to intlut().
댓글 수: 2
Image Analyst
2012년 7월 14일
Several confusing/contradictory things in your comment. If the histogram is 0,3,5,6 that means you have 0+3+5+6 = 14 objects, not 6 objects. But hist uses 10 bins so you should have 10 numbers, not 4 - what happened to the other numbers? But with 10 bins there might be groupings/binnings we don't want. Therefore, try this:
[numberOfObject binValue] = hist(LL(:), max(LL(:)))
so that we have one bin for exactly one label number. If your labels go as high as 8, you should have 8 bins and 8 values for the bins (one value per bin). Of course you need to do this on LL before you change its values. The numbers will still add up to be 14 though and that is confusing because you say there are 8 objects not 14.
Finally, you didn't answer why you want the labels renumbered. Like I said, it's not necessary. And you didn't say why (if you still insist on renumbering) you didn't use intlut() instead of that for loop.
추가 답변 (2개)
Walter Roberson
2012년 7월 9일
[tf, idx] = ismember( Mk, {'Water', 'Soil', 'Trees', 'Vegetation', 'Building', 'Shadow'} ); %and add the other two cases
LLsubset = (LL >= 1 & LL <= Num);
LL( LLsubset ) = idx( LL( LLsubset ) ) * 100;
댓글 수: 3
Walter Roberson
2012년 7월 9일
You have 8 classes in Mk but only test 6 of them ?
What do you observe when a label is "lost" ?
Dimitris M
2012년 7월 13일
댓글 수: 2
Image Analyst
2012년 7월 14일
At this point I think the only way we can make progress in helping you is for you to upload you LL file. Pick your favorite file hosting web site and let us know what the URL is. And tell us exactly how you create Mk.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!