Matlab tiff setTag number not recognized - matlab

I am trying to change the value of a tag from a TIFF object in my matlab code. I keep getting this error:
Error using tifflib
Tag number (273) is unrecognized by the TIFF library.
Error in Tiff/setTag (line 1146)
tifflib('setField',obj.FileID, ...
The code I am using is included below:
fname='C:\FileLocation\pcd144_012.tif';
t=Tiff(fname,'r+');
t.getTag('StripOffsets')
t.setTag('StripOffsets',[8, 16392])
Why is it I can get the tag and see it, but cannot set the tag to a different value?
Here is a link to the tiff I am working with:
Tiff Data

I think that you're out of luck with this approach. The setTag methods are mostly used when building a TIFF from scratch. My guess is that the 'StripOffsets' field is not modifiable. Keep in mind that these tools are designed for the normal case of non-broken image files and that changing this field in such cases would either break the file or necessitate re-encoding of the data most of the time. The function should give better feedback (documentation for the TIFF could be better in general) so you might still contact The MathWorks to let them know about this.
As far as finding a way to edit these tags/fields, you might look for and try out some TIFF tag viewer/editor programs to see if they might do it. Otherwise it may come down to parsing the header yourself to find the relevant bytes.

Related

Most efficient way to change the value of a specific tag in a DICOM file using GDCM

I have a need to go through a set of DICOM files and modify certain tags to be current with the data maintained in the database of an external system. I am looking to use GDCM. I am new to GDCM. A search through stack overflow posts demonstrates that the anonymizer class can be used to change tag values.
Generating a simple CT DICOM image using GDCM
My question is if this is the best use of the GDCM API or if there is a better approach for changing the values of individual tags such as patient name or accession number. I am unfamiliar with all of the API options but have a link to the API documentation. It looks like the DataElement SetValue member could be used, but it doesn't appear that there is a valid constructor for doing this in the Value class. Any assistance would appreciated. This is my current approach:
Anonymizer anon = new Anonymizer();
anon.SetFile(myFile);
anon.Replace(new Tag(0x0010, 0x0010), "BUGS^BUNNY");
Quite late, but maybe it would be still useful. You have not mention if you write in C++ or C#, but I assume the latter, as you do not use pointers. Generally, your approach is correct (unless you use System.IO.File instead of gdcm.File). The value (second parameter of Replace function) has to be a plain string so no special constructor is needed. You should probably start with doxygen documentation of gdcm, and there is especially one complete example. It is in C++, but there should be no problems with translation.
There are two different ways to pad dicom tags:
Anonymizer
gdcm::Anonymizer anon;
anon.SetFile(file);
anon.Replace(gdcm::Tag(0x0002, 0x0013), "Implementation Version Name");
//Implementation Version Name
DatsElement
gdcm::Attribute<0x0018, 0x0088> ss;
ss.SetValue(10.0);
ds.Insert(ss.GetAsDataElement());

Read / run a MATLAB script from a URL

Fairly simply question, but I cannot find an answer via Google or on Stack.
I have a use-case where it would be highly-preferable to simply read a .m MATLAB script from a URL.
How should I do this correctly?
<disclaimer>
Clearly only do this with files you have complete control of (and/or find a solution with better validation). This is a "dangerous" method as there is no check that you're not about to run a file which, for example, copies your entire harddrive to Bob's computer before corrupting it all. Bob and Alice might be spending the whole evening laughing at your embarrassing holiday photos.
Treat this more as a proof of concept than a how-to, it addresses your problem but by no means should be used in production code.
</disclaimer>
You'll need to use eval to evaluate code. Every time I mention eval I feel compelled to point out it's not recommended, in particular in this case because you could be evaluating whatever random code is living in that file on the web! In this case your only alternative is to save the file locally and call run.
Then you can use
eval(urlread('http://myscript.m'))
or, since urlread is not recommended (from the docs), you can use webread and specify that the output should be text in the options
eval(webread('http://myscript.m', weboptions('ContentType', 'text')))
Using webread appears to be really slow, not sure why when it's the recommended function. In light of this, urlread might be preferable.
There is a note in the webread docs which suggests you wouldn't even need to specify the weboptions
If a web service returns a MATLABĀ® file with a .m extension, the function returns its content as a character vector.
Although you suggested that webread returned a uint8 variable which didn't work.
If you'd like to save a file from a URL then run it, you can use websave and str2func like so:
fcnName = 'newscript'; % Name for the function/script file
websave([fcnName '.m'], 'http://myscript.m'); % Download and save it
fcn = str2func(fcnName); % Create function handle
fcn(); % Evaluate function/script
It should of course go without saying that you want to be really sure you can trust the source of the file, otherwise you're gonna have a bad time.

How to best possibly protect .m file?

I have an .m file which I wish to share with my friends but I am not interested in giving .m file. Could someone help me with best possible ways to convert it to a file that is not decodable?
I tried converting it to .p file by simply typing pcode example.m
however I don't believe it is really protecting it. I was able to convert my .p file back to .m file with the following link. https://sites.google.com/site/sippeyfunlabs/matlab-hacks/please-do-not-secure-your-password-in-matlab-p-code
This actually confirms that my code is not protected.
It'll be nice if someone shares the best methodology to protect .m file and sharing.
Thanks
The link you provided yourself already indicates that it is very difficult to obfuscate MATLAB code:
In fact, MATLAB language is very difficult to be secured or even obfuscated.
This is due to the late binding (or dynamic binding) feature of
MATLAB. [...] The amount of meta information associated with this
feature basically forbid any attempt of adding code level security.
Simply put, if there is a MATLAB file, and it calls a function foo
inside it. Until the runtime, the MATLAB interpreter do not even know
if foo is a function stored in M file or a built-in function or a mex
function or even a workspace function handle. Thus, it must store foo
as is somewhere inside the generated P-code.
Also to best solution is already mentioned on that page:
If there is really a need to do this, using the good old binary is a
much better solution. Or you can put critical code on a server, away
from the user.
Create a binary, i.e. mex file (see the answer of Wolfie): Note that to some extent also binary code can be decompiled especially small ones.
Host your code on a server (and run the code server-side): This is the best method to protect your code. You should let the user upload the input for your script and return the result. You can also automatize this process using a matlab script to make this process transparent to the user.
You could build a mex file.
This will completely obfuscate your actual MATLAB code, since it will be written in C/C++/FORTRAN, but the algorithms will still be there if your friends are determined enough to look for them.

How do I train tesseract but not create a new language?

So I am trying out tesseract at the moment, and it does work, but it is not accurate enough. I know that the image quality plays a role as well, etc. etc., but some of the documents I am using use a rather unusual font. It still does recognise parts of it though (about 50-60%, which is pretty good), but this is obviously not entirely satisfying.
I would like to know now whether it's possible to train tesseract, but not to create an entirely new language, but to use the data I am already using, and build on this and improve it?
Second, if this is possible, would this even be advisable? Or (2) would it be better to create new languages for every new font I encounter, or (3) create new languages for each new font I encounter, but not from scratch but always built upon the default data I am using right now? What do you think? If you can provide any links on how to train tesseract & make use of the training data already provided, do let me know please.
You can extract the files from .traineddata file as given in documentation :
specify option -u to unpack all the components to the specified path:
combine_tessdata -u tessdata/eng.traineddata /home/$USER/temp/eng.
This will create /home/$USER/temp/eng.* files with individual tessdata components from tessdata/eng.traineddata.
There are other options too,please check the documentation on the following link.
https://github.com/tesseract-ocr/tesseract/blob/master/doc/combine_tessdata.1.asc
But rather than playing with original files its advisable to train tesseract for a new language.
(2)You dont have to create new language for each font.You have to create image,box and training file for each font .All of these will then be combined into a single language's traineddata file.
(3)This is possible too.PLease visit
https://github.com/tesseract-ocr/tesseract/wiki/Training-Tesseract-3.00%E2%80%933.02#bootstrapping-a-new-character-set

How to get the content of an embedded MATLAB function

In my Simulink model are some embedded MATLAB functions. Is there a way to get the content (the text you see in the editor) of this blocks?
My first guess was to use find_system to get the embedded MATLAB functions and then get_param to get the content. But I dont find the needed parameter name. The documentation didnt show up any parameter for the embedded MATLAB functions.
Try this technical solution on the Mathworks website.