Problem when changing labels in image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 13 Jul. 2012
Bearbeitet: Image Analyst
am 13 Jul. 2012
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 Kommentare
Image Analyst
am 14 Jul. 2012
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.
Weitere Antworten (2)
Walter Roberson
am 9 Jul. 2012
[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 Kommentare
Walter Roberson
am 9 Jul. 2012
You have 8 classes in Mk but only test 6 of them ?
What do you observe when a label is "lost" ?
Dimitris M
am 13 Jul. 2012
2 Kommentare
Image Analyst
am 14 Jul. 2012
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.
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!