imshow() for multiple selected objects
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi,
I have an image with ~200-250 labeled objects. How can I use imshow() to display multiple selected objects?
When I try this:
imshow(LL == 200)
It works to show the object labeled 200. Say I want to see 200 and 201. I tried:
imshow(LL == 200)
hold on
imshow(LL == 201)
This erases 200 and shows just 201.
Thanks for your suggestions and tips!
채택된 답변
Ameer Hamza
2020년 10월 6일
0 개 추천
image(): https://www.mathworks.com/help/matlab/ref/image.html is better suited for this case. Or even pcolor(): https://www.mathworks.com/help/matlab/ref/pcolor.html.
댓글 수: 11
Veena Chatti
2020년 10월 6일
Thanks- any idea how to use these to specify objects from a labelmatrix?
Ameer Hamza
2020년 10월 6일
Can you clarify? Do you want to give different colors to each label? Can you attach the matrix?
Veena Chatti
2020년 10월 6일
Thanks- here are the following attachments:
- Image containing all the objects (colored by 'turbo' and 'shuffle' with label2rgb)- allobjects.png
- The labelmatrix of these objects- LLlabelmatrix.mat
- The RGB values from label2rgb- RGBvaluesfromlabel2rgb.mat
- The colormap I extracted, with the corresponding label in column1 - colormapandlabel.mat
I hope these clarify what I'm trying to do- I have many such images as allobjects.png in a time-series, and I'd like to give an object the same color it had in another image when it is correctly tracked between the images.
Thanks for taking a look!
Veena Chatti
2020년 10월 6일
By the way, imshow() works just fine to show one object (white, with black background). Just trying to figure out how to get it to show multiple labels at a time, with the right colors assigned by 'turbo'.
This code shows how you can use the colormap with image() to define the color of each region.
colormap(clmp(:, 2:end))
p = image(LL, 'CDataMapping', 'direct');
Veena Chatti
2020년 10월 6일
Thank you, Ameer Hamza! This works like a charm to give it the same colormap.
Can you explain a little about the logic behind 'CDataMapping'? I took a look at the documentation. It says:
"Color data mapping method, specified as 'direct' or 'scaled'. Use this property to control the mapping of color data values in CData into the colormap. CData must be a vector or a matrix defining indexed colors. This property has no effect if CData is a 3-D array defining true colors.
'direct' — Interpret the values as indices into the current colormap. Values with a decimal portion are fixed to the nearest lower integer.
If the values are of type double or single, then values of 1 or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap."
So if I understand this correctly, it assigns them the same map, but since the objects might move between frames, the object indices/labels change. If I can get the object labels to stay the same, in the same order, will it give each label the same color?
Ameer Hamza
2020년 10월 7일
Yes, this is exactly what it means. It uses the label to decide which row of colormap to use. If you want to show two objects with the same color between frames, just give them the same label number.
Veena Chatti
2020년 10월 7일
- The same label number and the same position/index in the list of labels? Or just the same label number?
- Also, is there a way to set the zerocolor while using the image() command?
Thanks very much for all your help with this!
You only need the same label numbers in the 2D matrix and the same rows in the colormap. image() function just read the label value at a location in the matrix, go to that row in colormap and use that color.
According to documentation, by default, 0 value (or any negative value) is mapped to 1st color in the colormap. To give different color to 0, replace 0 with a different number. For example, currently, your matrix has 257 labels (if I remember correctly). Replace 0 with 258
LL(LL==0) = 258;
and then add a new row to the colormap too
cmap = clmp(:, 2:end);
cmap = [cmap; 0 0 0]; % black color is added at 258 row in colormap
colormap(cmap)
Veena Chatti
2020년 10월 7일
Thank you! I think I am beginning to follow the logic of how image() works. The trick is to find a way to get it to retain the labels while tracking the objects now.
I really appreciate all your help. Thanks again!
Ameer Hamza
2020년 10월 7일
I am glad to be of help! :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Red에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
