ISET / isetcam

Open source version of the original ISET, a complement to ISETBIO
MIT License
133 stars 51 forks source link

Questions about the focal length calculation formula in `opticsCreate.m` #35

Closed hjbiao09 closed 6 months ago

hjbiao09 commented 6 months ago

Hello. Firstly, thank you so much for releasing such an amazing repository.

While viewing this repository, I have a question about the initializationof the diffraction limited case in OpticsCreate.

in opticsCreate.m, we can see the following codes.

% Standard 1/4-inch sensor parameters
sensorDiagonal = 0.004;
FOV = 46;
fLength = inv(tan(FOV/180*pi)/2/sensorDiagonal)/2;

First, if I convert sensor diagonal from inches to m, I believe .25 / 0.0254 = 0.00635 is correct, not 0.004. And in the formula for focal length, it says tan(FOV/180*pi)/2 --> $fLength = \frac{2sensorDiagnoal}{2tan(\frac{FOV \pi }{180})}$. But if the formula is calculated using trigonometry, I think the FOV should be divided by 2, so /2 part should be in the tan. So I think the formula should be `fLength = inv(tan(FOV/180pi /2)/sensorDiagonal)/2`. $fLength = \frac{sensorDiagnoal}{2tan(\frac{FOV \pi }{1802})}$.

I hope you can review if my thinking is correct. Once again, thank you so much for opening up your amazing source.

digital-pro commented 6 months ago

I'll take the firs question. Many sensor format names derive from the physical properties of CRTs (where only part of the size was usable). So a 1/4-inch "format" sensor has the same usable area as a 1/4-inch CRT, which is around a 4.5mm diagonal.

wandell commented 6 months ago

Thanks for your kind words. Adding to Dave Cardinal’s comments.

  1. To repeat Dave’s point, the ¼ inch name is really, just a label. It derives from industry terminology and it is not a real unit description. I should have a comment about this in the text. Here is a summary of various sizes. https://www.perplexity.ai/search/Image-sensors-say-G7JLVxXaQcuQW3vi2_clXw. I put in those labels 20 or 25 years ago. Probably I should comment or remove them. The standards rarely matter much.

  2. Concerning the focal length formula, you are right. I am going to explain at length below – for my notes and the record. This formula would not have shown up as a bug in our testing for reasons I also explain below. But it is a bug and I will change the code shortly. Have a look at the plan.

The geometry is this: @.*** We can now use the Matlab tangent in degrees function (tand) to simplify

tand(FOV/2) = (sensorDiag/2)/fLength (tangent of the angle is opposite over adjacent)

So,

fLength = (sensorDiag/2)/tand(FOV/2)

Pretty simple. But comparing, as you did!, the formula is wrong. But I don’t want to change the formula. Instead, I want to simply set the focal length to its current value (0.0039). Here is why.

The diffraction limited optics depends only on the focal length and fnumber. Over the years, these were set to 0.0039 (focal length) and fNumber (4). Everything else is derived. The coding error I made means that the FOV was not correctly 46 deg for the ¼ inch sensor.

But nothing about the optics calculations depend on the sensor (which could be bigger or smaller). If I correct the formula, many of the carefully constructed validations testing the diffraction optics will fail. There are tons of validations.

So, I propose to correct the code by replacing the formula by simply setting fLength to the old value of 0.0039. This implicitly sets the FOV for a ¼ inch sensor to be a bit larger, which is what I guess we were inadvertently living with for all these years.

2atand(((sensorDiag/2)/fLength) = 2atand( (0.002/0.0039)) = (54 deg)

Make sense?

Brian

From: junpyo hong @.> Date: Wednesday, May 1, 2024 at 7:16 PM To: ISET/isetcam @.> Cc: Subscribed @.***> Subject: [ISET/isetcam] Questions about the focal length calculation equation formula in opticscreate.m (Issue #35)

Hello. Firstly, thank you so much for releasing such an amazing repository.

While viewing this repository, I have a question about the initializationof the diffraction limited case in OpticsCreate.

in opticsCreate.m, we can see the following codes.

% Standard 1/4-inch sensor parameters

sensorDiagonal = 0.004;

FOV = 46;

fLength = inv(tan(FOV/180*pi)/2/sensorDiagonal)/2;

First, if I convert sensor diagonal from inches to m, I believe .25 / 0.0254 = 0.00635 is correct, not 0.004. And in the formula for focal length, it says tan(FOV/180pi)/2. But if the formula is calculated using trigonometry, I think the FOV should be divided by 2, so /2 part should be in the tan. So I think the formula should be fLength = inv(tan(FOV/180pi /2)/sensorDiagonal)/2.

I hope you can review if my thinking is correct. Once again, thank you so much for opening up your amazing source.

— Reply to this email directly, view it on GitHubhttps://github.com/ISET/isetcam/issues/35, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAOAQWIKHCC6UH5VYEK2H2LZAGOY7AVCNFSM6AAAAABHC33BWGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3TINBWG4YTINI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

digital-pro commented 6 months ago

Brian -- Thanks for the great explanation Quick thoughts

On 1) I'd keep the labels "someplace" as (silly as they are) they are used incredibly-widely in the consumer camera industry. But it would be good to do what we can to avoid this common confusion.

On 2) That's fine with me, or I suppose we could fix the formula but set the FOV to 54? Or would that break other things? In any case, hard-wiring it is certainly plenty good. -- David

wandell commented 6 months ago

Good. Then, two quick things.

There is a function called sensorFormats that I forgot about. It defines these numbers according to industry standards back in 2005 or so.

Concerning opticsCreate, here is the replacement code. I followed your suggestion to leave it as a formula, but make the numbers match so the validations would pass.

    % For some years, we derived the focal length using an
    % incorrect formula
    %
    % FOV = 46;
    % sensorDiagonal = 0.004;
    % fLength = inv(tan(FOV/180*pi)/2/sensorDiagonal)/2;
    %
    % The correct formula with the parameters that preserve
    % validation, we have
    FOV = 54.747093438872568;
    sensorDiagonal = 0.004;
    fLength = (sensorDiagonal/2)/tand(FOV/2);

The ieValidation(‘isetcam’,’validation’) pass with this. I am going to commit to ‘dev’ and ‘master’ shortly.

Brian

From: David Cardinal @.> Date: Thursday, May 2, 2024 at 11:27 AM To: ISET/isetcam @.> Cc: Brian A Wandell @.>, Comment @.> Subject: Re: [ISET/isetcam] Questions about the focal length calculation formula in opticsCreate.m (Issue #35)

Brian -- Thanks for the great explanation Quick thoughts

On 1) I'd keep the labels "someplace" as (silly as they are) they are used incredibly-widely in the consumer camera industry. But it would be good to do what we can to avoid this common confusion.

On 2) That's fine with me, or I suppose we could fix the formula but set the FOV to 54? Or would that break other things? In any case, hard-wiring it is certainly plenty good. -- David

— Reply to this email directly, view it on GitHubhttps://github.com/ISET/isetcam/issues/35#issuecomment-2091228720, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAOAQWOR6VPTXZ5FZYUNXCDZAKAPTAVCNFSM6AAAAABHC33BWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJRGIZDQNZSGA. You are receiving this because you commented.Message ID: @.***>

hjbiao09 commented 6 months ago

Thank you both very much for your quick responses. Both questions have been answered and the formula will be modified for better readability in the future, so this issue will be closed. Thanks a lot!