I have an image, where the colors correspond to height. Please refer to below image. On the colormap spectrum: Blue is -500 meters Red is +500 meters
1) I want to Make plot for the height along Line 1
2) Make plot for the height along Line 2
3). Create a 2D array for the height values for the image. Basically, for every pixel position, give a corresponding height value. For simplicity, you can assume the grey pixels have a value of -1000 m.
Your help will be much appreciated.
Thanks in advance.

댓글 수: 12

Walter Roberson
Walter Roberson 2021년 3월 14일
That is homework and you have not shown any effort.
There is not enough information to solve the problem. Giving two color endpoints does not tell you how height varies with color.
Walter Roberson
Walter Roberson 2021년 3월 14일
Are we to assume that depth is linear with difference in hue? https://www.researchgate.net/figure/a-RGB-b-HSV-color-space_fig2_335470954
Adnan Khan
Adnan Khan 2021년 3월 14일
I have tried things but it didn't work. I segmented the foreground and background, and tried to measure the end points, I also tried to use color thresholder app of matlab. But I don't have clear direction on how to apply my efforts to tackle this problem.
Adnan Khan
Adnan Khan 2021년 3월 14일
If there is not enugh information, then what assumptions do we need to solve it? What information/parameters do we need in addition to the ones specified in probelm statement?
Walter Roberson
Walter Roberson 2021년 3월 14일
If we were permitted to assume that depth is linear in angle of difference of hue, then convert to hsv, and find the hue channel difference compared to pure blue and do linear interpolation.
Adnan Khan
Adnan Khan 2021년 3월 14일
Thank you, I will try this.
Adnan Khan
Adnan Khan 2021년 3월 14일
In the third step, after finding the hue channel, you want me to subtract it from pure blue?
Walter Roberson
Walter Roberson 2021년 3월 14일
Hue is an angle. Pure red is 0. If you head one direction around the circle then blue is 120 degrees away. If you head the other direction around the circle then 120 degrees is green and blue is 240 degrees. You need to study the diagram I linked to and experiment with rgb2hsv to figure out which direction you need to travel and what values rgb2hsv uses to represent the angles.
Adnan Khan
Adnan Khan 2021년 3월 14일
Sir I studied that. What I observed is that after going to hsv scheme we have values in the range 0 to 1. I am not quite sure if I am correct but 0 corresponds to angle 0 and 140 degrees in the blue direction corresponds to a fraction 140/360 = 0.3888. You may like to see what I have tried up until now.
Original Image
Converted to HSV
Now since the problem statement says that color corresponds to height, here in hsv the whole circle is of same color 'Cyan'. In hsv its angle is 180 degrees between the green and blue. In response to your comment, I would say I need to travel 180 degrees to reach this color (Not sure I may be wrong). But how do I find height out of it Sir?
timg = permute([1 0 0; 0 0 1], [3 1 2])
timg =
timg(:,:,1) = 1 0 timg(:,:,2) = 0 0 timg(:,:,3) = 0 1
image(timg)
thsv = rgb2hsv(timg)
thsv =
thsv(:,:,1) = 0 0.6667 thsv(:,:,2) = 1 1 thsv(:,:,3) = 1 1
thue = thsv(:,:,1)
thue = 1×2
0 0.6667
Pure red has a hue of 0. Pure blue has a hue of 2/3.
Pure red corresponds to a height of +500 meters. Pure blue corresponds to a height of -500 meters.
A*0 + B = 500
A*2/3 + B = -500
Subtract. 2*A/3 + (B-B) = -500 - 500 --> 2*A/3 = -1000 --> 2*A = -3000 -> A = -3000/2 --> A = -1500.
You should be able to work out B easily from this, and from that you should easily be able to calculate the formula that maps hue to height in your system.
Remember, Hue is the first pane of an HSV image, not all of the panes.
Adnan Khan
Adnan Khan 2021년 3월 16일
Thanks sir for your kind help.
Adnan Khan
Adnan Khan 2021년 3월 16일
Accept answer tab is not appearing here. I want to accept the procedure you told because it worked. Thanks once again.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 17일

0 개 추천

(Moving down from comments)
timg = permute([1 0 0; 0 0 1], [3 1 2])
timg =
timg(:,:,1) = 1 0 timg(:,:,2) = 0 0 timg(:,:,3) = 0 1
image(timg)
thsv = rgb2hsv(timg)
thsv =
thsv(:,:,1) = 0 0.6667 thsv(:,:,2) = 1 1 thsv(:,:,3) = 1 1
thue = thsv(:,:,1)
thue = 1×2
0 0.6667
Pure red has a hue of 0. Pure blue has a hue of 2/3.
Pure red corresponds to a height of +500 meters. Pure blue corresponds to a height of -500 meters.
A*0 + B = 500
A*2/3 + B = -500
Subtract. 2*A/3 + (B-B) = -500 - 500 --> 2*A/3 = -1000 --> 2*A = -3000 -> A = -3000/2 --> A = -1500.
You should be able to work out B easily from this, and from that you should easily be able to calculate the formula that maps hue to height in your system.
Remember, Hue is the first pane of an HSV image, not all of the panes.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 White에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2021년 3월 14일

답변:

2021년 3월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by