Leica M8 bad Line interpolation. Or what you can do with Three lines of Fortran

Sonnar Brian

Product of the Fifties
Staff member
Local time
8:53 PM
Joined
Jan 12, 2004
Messages
18,616
BLUF- I've been using M8RAW2DNG since it was first out. I still use it. Produces uncompressed DNG, and slightly larger images. It is very easy to read the DNG files and work with them. A while ago I wrote custom code to produce color IR images using an Orange filter with the M8. You must use M8RAW2DNG to equalize the colors. The same code was quickly modified to average out Bad Columns that popped up on my friend's Leica M8. One of our forum members also suffered the same problem.

C SIMPLE AVERAGE OF VALUES.
DO 5 J= 1, BADROW( LINE)
IMAGE( BAD, J)= ( IMAGE( BAD- 2, J)+ IMAGE( BAD+ 2, J))/ 2
5 CONTINUE

Simple averaging scheme.

L1085619_Cropped_Badline.jpgC1085619_crop_Fixed.jpg

I used "ART" to generate the jpegs from the 20MByte DNG files, used the pixel locater of the images. Whatever ART shows the column number, add 5 to get the actual stored column number.

At some point- I'll write a version of the code that works with the M8 compressed DNG files. They are 8-bit values derived from a square root function. Do not get me started on how bad the scheme is, everyone knows I hate it.
storedvalue= sqrt( pixelvalue* 4)
pixelvalue= ( storedvalue** 2)/4

Okay- two lines of Fortran. BUT- I need to modify the arrays and read/write routines to actually get to them...
 
FORTRAN!

I recall the days of punch cards, especially when I put a character in the wrong column and it ended up printing about 1000 pages...one char per page. The guys at the university computer lab weren't pleased...
 
FORTRAN!

I recall the days of punch cards, especially when I put a character in the wrong column and it ended up printing about 1000 pages...one char per page. The guys at the university computer lab weren't pleased...
One time I printed a object file by mistake and the paper was ejecting from the line printer so fast it almost hit the ceiling. I was in the computer room and terminated the job. Days of perforated paper and the big printers.

If I'm not writing code in Fortran, it's because I'm writing assembly.
 
  • Like
Reactions: dct
For this particular program, "COLORFIX"- it runs in a command line window. Set it to the directory with the DNG files in it, type "COLORFIX" at the prompt, and just hit Enter for both inputs. It produces new DNG files with a "C" replacing the "L" in the filename. You can also apply a Gamma curve to the image, and get "G" for the name- all numbers the same. "Batch" processing.

REMEMBER!

"In FORTRAN there is no TRY, there is only DO!"
Which is why Jedi Masters use it.
 
At a SIGPLAN conference .... this was sometime in the mid 1990s? ... I was told this anecdote: Apparently Backus was delivering a keynote (perhaps for this same conference at some earlier date?) when he talked about the design of Fortran and lamented that he "forgot the recursion!"

This maybe is one of those stories that we all wished was true ...
 
My wife's teacher for a Masters Level course in engineering stated that FORTRAN cannot do recursion.

Fortran lets you pass a function name as an argument to a function.

I pass the Function as an argument to Itself. It works because the compilers allocate local storage off the Stack.

PROGRAM FACTOR
IMPLICIT NONE
INTEGER* 4 NUMBER
INTEGER* 4 FACTRL
EXTERNAL FACTRL
5 CONTINUE
WRITE( *, *) 'INPUT A NUMBER FROM 0 TO 69: '
READ( *, *) NUMBER
IF( NUMBER .LT. 1 .OR. NUMBER .GT. 69) STOP 'NORMAL END'
WRITE( *, 100) NUMBER, FACTRL( NUMBER, FACTRL)
100 FORMAT( 1X, I3, '! IS ', I10)
GO TO 5
END

INTEGER* 4 FUNCTION FACTRL( NUMBER, MYSELF)
IMPLICIT NONE
INTEGER* 4 NUMBER, MYSELF
IF( NUMBER .EQ. 0) THEN
FACTRL= 1
RETURN
ELSE
NUMBER= NUMBER- 1
FACTRL= MYSELF( NUMBER, MYSELF)* ( NUMBER+ 1)
END IF
END

But remember- Recursion is the Enemy of Efficiency.
 
Last edited:
FORTRAN!

I recall the days of punch cards, especially when I put a character in the wrong column and it ended up printing about 1000 pages...one char per page. The guys at the university computer lab weren't pleased...
So do I. And Brian is trying to tell us that he uses a program written in a thousand year old language to convert Leica M8 files???
 
"My wife's teacher for a Masters Level course in engineering stated that FORTRAN cannot do recursion."

OK I have MSME and am curious where does you wife go to college? Not to knock this, just curious. I am a semi-retired Systems Nuclear Engineer and a not too many years ago while working for a major (i.e. one of two) Nuclear Engineering design firms I took a course in accident analysis. It amazed me that the computer code was written in Fortran and a lot of the course dealt with how to enter data with current Windows software to be understood by Fortran. Depressing,
 
If I'm not writing code in Fortran, it's because I'm writing assembly.
A good one!
After 2 years of 6503 direct machine language (peek, poke) for some Commodore routines, I went through 10 years of Assembly programming. It was mostly fun, having every Byte and bit under exact control.
My apologies that I cannot contribute to the topic itself. It did just trigger my memory.
 
I'm not a programmer but did need to use UNIX in the 90's and learned how to customize my .cshrc shell environment and use some light automation commands and aliases. This cartoon always cracked me up (can't find the original with the cavemen/modern men then and now language comparison):

iu
 
"My wife's teacher for a Masters Level course in engineering stated that FORTRAN cannot do recursion."

OK I have MSME and am curious where does you wife go to college? Not to knock this, just curious. I am a semi-retired Systems Nuclear Engineer and a not too many years ago while working for a major (i.e. one of two) Nuclear Engineering design firms I took a course in accident analysis. It amazed me that the computer code was written in Fortran and a lot of the course dealt with how to enter data with current Windows software to be understood by Fortran. Depressing,
She got her masters in Biomedical Engineering at George Washington University.

I can list my 10 rules for Program like a Klingon. Rule #1 "all that matters is execution speed".

What surprises me about other programming languages- handling of arrays still allows for the "one off" problem, and that the programmer has to do a lot of math for multi-dimensional arrays. Multi-dimensional arrays are essentially "arrays of 1D arrays". Fortran arrays are much closer to how they are used in Matrix Math and Storing images from sensors. SO- get the starting address of the image file in a DNG file, get the columns and rows: then pass it to the function declaring the Two-Dimensional array with those values.
DNG file in 1D Byte array Buffer, Image Tags give the beginning of image data, now in TIMAGESTART

CALL COLORMOSAIC( BUFFER( TIMAGESTART), TCOLUMNS, TROWS)
NEWTAGS= IFDCONVERTIR( BUFFER( 10), BUFFER( 10), BUFFER( 10),
1 OLDTAGS)

...
Pass the buffer and declare as a 2D image in the routine. This routine converts M8 images taken with an Orange filter (Blue channel gets IR only) to Color-Infrared images with an IR Ektachrome look.

SUBROUTINE COLORMOSAIC( IMAGE, COLUMNS, ROWS)
IMPLICIT NONE
C IMAGE GENERATED USING EQUALIZATION.
C 1) COMPUTE HISTOGRAM FOR ALL THREE CHANNELS.
C 2) INTEGRATE AREA UNDER HISTOGRAM AND NORMALIZE.
C 3) EQUALIZE BLUE AND GREEN TO RED.
INTEGER* 4 COLUMNS, ROWS
INTEGER* 2 IMAGE( COLUMNS, ROWS)
 
Last edited:
There may be two chuckles in this post.

The first is that I still have all of my card decks for the programs I wrote while attending school.

I was first introduced to computing and Fortran IV at the System Simulation Lab at USC in Southern California. They had an IBM 360/44 mainframe. At the time, that was sort of a junior computer in the 360 family. I loved learning Fortran and took to it like a duck to water. However, I was still extremely new to computer science and the equipment. During the very first week we got a tour of the machine room. It was the first time I’d seen an actual computer. I looked at the rows of console lights, the toggle switches, the dials. I then asked the most important question that was on my mind:

“Where is the compiler?”

I thought it had to be right behind the console.

They calmly explained that the compiler was a program. Well, that did it. I was hooked.

From there I went on to get a Computer Science degree from UCLA and was fascinated with compilers, assemblers, all the development tools.

On my first computer-related job I became fascinated with peripherals and I/O and from there became interested in firmware development. Which is where I am these many decades later.

Later, I’ll post a photo of one the cards from the lab.
 
That's really cool, Brian! I'd love to try that out on my M8.2.

I've used M8RAW2DNG before, but not recently. It appears that the site I downloaded it from (M8RAW2DNG.de) is now a spam generator. Do you happen to know if there's a live site somewhere with a Windows binary?

I've somehow never used Fortran, and I kind of regret it. A little Cobol, loads of BASIC dialects, LOGO, some Lisp, C, some 6502 assembly. But no Fortran.
 



I have the .exe file backed up, along with the original documentation and my notes for HIGH ISO.

Arvid wrote the code to go with his M8. I suspect he has moved on. I get every last pixel out of mine.
 
Back
Top