cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - You can change your system assigned username to something more personal in your community settings. X

3-Visitor

## 16-bit image processing in Prime 8

I have 16-bit TIFF images I need to analyze.  But, it seems that Mathcad Prime 8 (and 7 before) only reads them as 8-bit.  Mathcad 15 read them correctly to their full bit depth, but Prime does not.  Does anyone know how to read 16-bit images to their full depth?  (I also have 12-bit JPGs with the same problem, Prime reading them only as 8-bit.)

Thank you, KK

1 ACCEPTED SOLUTION

Accepted Solutions
21-Topaz I
(To:KK_7610519)

Keith,

Put the files into one directory.

Scilab commands to read the files, convert to doubles, and save to text files are simple.  This gives larger file sizes.

To use binary files is possible with a few more statements than this.  Doing thousands of photos I would use binary to save space.

The variables from these statements look like this

The files are like this.

Can read the text files with Prime.  If used Prime can also read binary files.

The value of the maximum in the file is the maximum size of an unsigned integer

Zipped up the three text files

Scilab and computer vision toolbox also has the ability to save 16bit TIFF files after Prime has worked on them.

matlab and Prime cannot save 16 bit TIFFs

Cheers

Terry

15 REPLIES 15
21-Topaz I
(To:KK_7610519)

Hi,

Two solutions.

A) Use matlab which can read a 16bit TIFF image into a matrix, file the matrix as text, and you can open the text file into Prime.  This option costs a lot of money for matlab

B) Use SciLab (free software) with the additional free downloaded computer vision toolbox to read a 16bit TIFF image into a matrix, convert the integers to matrix of doubles, save the matrix of doubles to a text file, open the file in Prime.

Note: In Prime the Math | Regions | Image menu inserts a button click on the button and you can open a 16 bit TIFF file and Prime will show it.

Exasperation: There is no imshow(image) statement in the image processing function in Prime you have got to save the image then  insert the image using the above button.

If you want more detail on how to do it with the free SciLab give a shout out.

Cheers

Terry

Terry,

Thank you for the information you provided about my 16-bit image problem. I do have Matlab, but have not used it in a long time. So, I have installed Scilab as you suggested. It probably will take me quite a while to even get to the simple point of reading and saving an image, however, as I am kinda slow in learning new languages/interfaces. Any advice you can give regarding that will be greatly appreciated.

It is frustrating that Mathcad 15 would let me see the full 16-bit depth, but Prime does not. I did know I could view the actual image in Prime, but thank you for reminding me of that.

I hope your Thanksgiving time is good.

Keith Koenig (currently KK_7610519 on the PTC Community)
kk2@msstate.edu

21-Topaz I
(To:terryhendicott)

Hi,

Putting this in a separate post as it is important.

Mathcad used to be able to read matlab mat binary files.  SciLab can read and write matlab mat binary files.  Prime does not.  Mathcad could.  Another thing lost in translation Mathcad to Prime.

You need lines of commands in both matlab and SciLab to write a binary file Prime can read with READBIN.

Enough of the rant.

If you only have a few 16 bit TIFF images upload them and I can put them into Prime for you.  The task can be automated so quite a few files could be handled quickly.  Just zip the images and upload them here.  I'll post back the prime files.

Cheers

Terry

Terry,

Actually I have thousands of images, all successfully analyzed by Mathcad 15.  To make a short story long, we are looking at a new way to detect forest fires, and ran a series of tests last year, which included the "thousands of images".  We are starting a new measurement campaign and I was checking out my ability to analyze images.  That's when I realized Prime's bit limitation.

I have attached a sample of three images of burning pine needles.  The three images come from a single instance of the flame as viewed by three cameras we were using.  Each camera had a unique narrow band-pass optical filter to isolate certain features of the flames.  The C1, C2 and C3 in the file names indicate those cameras.

If it is not too much trouble, I would appreciate seeing what you are able to do with Scilab.  The images are 2560 x 2160 pixels, 16-bit monochrome (color makes wavelength isolation more difficult).

There is no hurry on this and if it is a problem for you, please say so!!  You have already provided a lot of help.

Happy Thanksgiving,

Keith

21-Topaz I
(To:KK_7610519)

Keith,

Put the files into one directory.

Scilab commands to read the files, convert to doubles, and save to text files are simple.  This gives larger file sizes.

To use binary files is possible with a few more statements than this.  Doing thousands of photos I would use binary to save space.

The variables from these statements look like this

The files are like this.

Can read the text files with Prime.  If used Prime can also read binary files.

The value of the maximum in the file is the maximum size of an unsigned integer

Zipped up the three text files

Scilab and computer vision toolbox also has the ability to save 16bit TIFF files after Prime has worked on them.

matlab and Prime cannot save 16 bit TIFFs

Cheers

Terry

Terry,

I apologize for the tardy response.  Your guidance has been extremely helpful; I am now able to do deal with these images.

Thank you,

Keith

24-Ruby V
(To:KK_7610519)

Do you still have a working copy of Mathcad 15?

If yes, you could read the file in in MC15, resave it in matrix format (e.g. with WRITEBIN) and read that file in in Prime (using READBIN).

3-Visitor
(To:Werner_E)
Thank you for the advice. Unfortunately, I do not have a working copy of 15. My license expired and could not be renewed when PTC ended their support for 15.

Keith Koenig

21-Topaz I
(To:KK_7610519)

Keith,

Here is the binary file version that takes a few more lines of SciLab commands.

The statement to read the binary file in Prime is:- Note you put the number of columns first then the number of rows!

24-Ruby V
(To:KK_7610519)

@KK_7610519 wrote:
Thank you for the advice. Unfortunately, I do not have a working copy of 15. My license expired and could not be renewed when PTC ended their support for 15.

Keith Koenig

Maybe the rudimentary TIFF reading function for Prime can be of any help.
I had not studied the TIFF specs so far, just poked around looking for the uncompressed data and the resolution information.

The function should therefore only be used with caution!

I guess that at least for uncompressed TIFFs it should be not that difficult (as long as you take the time and look more closely at the TIFF specifications) to write a more generic function which can deal with different resolutions, etc. as well.

24-Ruby V
(To:KK_7610519)

In case of the uncompressed TIFFs you posted, the data is there unchanged starting from word #9244 and so the pic easily can be read in in Prime and then turned into the proper matrix.

But you would have to dig into the specifics of the TIFF format to modify the function for pics of different resolution, etc. Its not a generic TIFF reading function!
The rudimentary function I provide will only work with pics of the very same format as the three pics you posted (uncompressed TIFF, 2160x2560, 16 bit, ...).

As we can see in MC15 the result is the same as when we use READ_IMAGE:

BTW, its a pity that even in MC15 the pics can't be shown with the full range of greyscale. It seems that what Mathcads image operator shows here are the 16 bit values modulo 256. A better display can be achieved by using the "scale" function, turning the pic matrix into a 8-bit grayscale (actually we get float values in the matrix but they are rounded by the image component).

Even worse that instead of implementing an improved image operator in Prime, PTC decided to leave it away completely.

Files in format MC15 and Prime6 attached

EDIT: Replaced files with new version of the function which is shorter and faster

3-Visitor
(To:Werner_E)

I understand the constraints you explained regarding the details of the TIFF files.  At least for the thousands of images I currently have, your method works perfectly.

Thank you,

Keith

3-Visitor
(To:Werner_E)

One last little thing, I should have indicated your method is also a solution to my problem.  I apologize for not doing so.

Keith

24-Ruby V
(To:KK_7610519)

@KK_7610519 wrote:

One last little thing, I should have indicated your method is also a solution to my problem.  I apologize for not doing so.

Keith

No problem at all.

Glad to hear that reading the Tiff pic and simply throwing away the first 9244 header bytes does the job for you. I guess that is because all your pics are equal in the sense that they stem from the same source with the very same settings used throughout.

3-Visitor
(To:Werner_E)
The photos are all taken in a lab with careful control of the three cameras so that they have the same settings.

We had 30 "Trials", each trial using three cameras, each camera taking 100 images (not video frames). So that is 30 x 3 x 100 = 9,000 images.

Again, your help is truly appreciated. Thank you.

Keith

Announcements
Top Tags