Is my question so difficult to get answered?
Info
This question is closed. Reopen it to edit or answer.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Why this incongruency happens regarding number of pixels?
1 view (last 30 days)
Show older comments
Hi
I use the image I attached.
I use this line to get the sum of pixels from row 307 to 366, at columns from 464 to 490
for col = 464 : 490
heights(col) = sum(rgbImage(366,col) - rgbImage(307,col));
end
This subtraction would give us 59 pixels and with a calibration factor of 0,042 it would give us around 2,48 mm for all the columns.
When I export the values to an excel file I get
If you multiply the below values with 0,042 you only get around 6 values acceptable and the closest to 2,5mm.
Why this incongruency???
By measuring heights(col), I should get 59 pixels multiplied by 0,042 I would get around 2,47 mm. Why I don't get those values when I export them to Excel??
Any ideas?
1
5
7
10
13
21
31
38
48
54
58
65
69
76
75
73
69
67
66
58
52
45
39
33
28
24
18
14
11 Comments
Stelios Fanourakis
on 24 Feb 2019
If I use this line
h(col) = imdistline(gca,[470 470],[307 366]);
I get correct results which is 59 pixels.
But when I try to export h(:) into an excel column I won't get anything.
Why the result of h won't be recorded in col (e.g. from 460:490)???
Rik
on 24 Feb 2019
"Is my question so difficult to get answered?"
You do realize this only discourages people from investing time and energy in your question?
As for your actual question: it is not really clear to me what is failing. Is everything inside Matlab going as it should but an export to Excel fails? Then what code are you using to do this export?
Also, it looks like the first 463 values would be 0. Did you check if the values start at row 464 in Excel?
Stelios Fanourakis
on 24 Feb 2019
@Rik
Yes Rik. Everything in the code is fine
I use this line to export to excel
data = [h(:)];
t = table(data);
writetable(t,'YourFile555.xls','Sheet',1,'Range','B1:B500')
Only with the imdistline I get no values recorded, where I should get 59 for all the columns I assign, since this is the actual number of pixels from row 307 to 366.
I assume that the command imdistline does not give out recording values. Do I have to convert it to another format in order to be recorded?
Rik
on 24 Feb 2019
The imdistline function returns an object. You will have to use one of the object functions for imdistline objects to retrieve the data you need.
Stelios Fanourakis
on 24 Feb 2019
@Rik. I don't understand the error. Can you help me please?
I use
for col = 464 : 491
h(col) = imdistline(gca,[col col],[307 366]);
dist(col) = getDistance(h)
end
And I get error
Expected one output from a curly brace or dot indexing expression, but there were 464 results.
Error in imline/getPosition (line 150)
pos = obj.api.getPosition();
Error in imdistline/getDistance (line 157)
pos = obj.getPosition();
Error in allo (line 101)
dist(col) = getDistance(h)
Stelios Fanourakis
on 24 Feb 2019
@Rik
Ok, this line works
h = imdistline(gca,[470 470],[307 366]);
dist = getDistance(h)
But it is just a vertical line for column 470. How can I make it have the same vertical line for each one of the columns starting from 460 to 490.
Rik
on 24 Feb 2019
I suspect you want something like this:
for col = 464 : 491
h = imdistline(gca,[col col],[307 366]);
dist(col) = getDistance(h)
end
Stelios Fanourakis
on 24 Feb 2019
Edited: Stelios Fanourakis
on 24 Feb 2019
Yes RIk. This was exactly the one that worked. Thanks a lot.
Can you please tell me the difference among sum() and imdistline()??
Using the sum command from row X1 to X2 and from column Y1 to Y2, I get different pixel values than the same reference points with imdistline.
Imdistline gives the right results. Why this incongruency?
Shouldn't be the same?
Image Analyst
on 24 Feb 2019
If you have an RGB image, why are you conly giving two indexes? It should have 3.
Perhaps you'd find improfile easier since it just returns x,y coordinates and you can find the end points easily from the first element and the last element of the coordinates.
Why are you summing the values?
Stelios Fanourakis
on 24 Feb 2019
Image Analyst. Can you please give me an example of how I could use the improfile command at my specific issue?
How I define X1,X2,Y1,Y2 and embed image as well. I have tried it in the past with no luck
Answers (1)
Image Analyst
on 24 Feb 2019
See attached spatial calibration demo. Adapt as needed.
5 Comments
Stelios Fanourakis
on 24 Feb 2019
@Image Analyst. I don't understand how this line works and how it can be related to my example
[cx, cy, rgbValues, xi,yi] = improfile(1000);
What is 1000??? Supposely, is my rgbImage at my example?
What are cx, cy and rgbValues?
How do I plug the X1,X2,Y1,Y2???
A little more help would be appreciated. Thank you
Image Analyst
on 24 Feb 2019
It's just taking 1000 samples along the line. It looks like you don't need the RGB values so you can ignore them and just look at cx and cy.
distanceInPixels = sqrt((cx(1)-cx(end)).^2 + (cy(1)-cy(end)).^2)
Stelios Fanourakis
on 24 Feb 2019
@Image Analyst.
I used this line that I must have modified by another previous code of yours
for col = 390 : 466
heights(col) = rgbImage(370,col) - rgbImage(215,col);
end
And the exported values in my excel are
6
6
6
7
9
11
13
15
12
11
9
7
7
12
17
21
26
27
26
25
25
24
28
33
37
41
43
36
28
19
11
10
15
20
27
32
33
32
32
31
31
43
53
62
75
81
81
80
79
78
74
69
63
58
52
52
53
54
55
53
47
40
31
25
19
16
13
9
6
8
12
16
20
24
21
17
14
Where I should actually get only 155 for all columns. Why the code line I used is not working properly? What is the wrong with it???
Stelios Fanourakis
on 24 Feb 2019
I guess this line
heights(col) = rgbImage(370,col) - rgbImage(215,col);
Does not make any arithmetic calculation. It is different than imdistline()
imdistline subtracts arithmetic number of pixels from point A to point B.
But by indexing the rows and columns of an image and making subtraction out of those, is totally different thing. Isn't it?
If not arithmetic subtraction then what?
Stelios Fanourakis
on 24 Feb 2019
I see. It is a subtraction of pixels values (intensity values), not the pixel as a number.
I double checked it.
Thanks for your time Image Analyst.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)