You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to decrypt a .mat file ?
25 views (last 30 days)
Show older comments
Hi,
Is there any way to go about this? I need an information on how to decrypt a given .mat file named "conf.mat" ?
I have to use this configuration file and make changes on its loaded parameters to suite my work.
Is there anyway this can be decrypted ?
Thanks
8 Comments
Chidiebere Ike
on 23 Oct 2018
I am using Matlab but can't seem to modify the .mat file content. I can as well use other tools if available. Thank you
Rik
on 23 Oct 2018
You can use the load function to load your variable to a struct, and then use save to write it back to the file. You have to jump through some hoops to automatically put all variables back into the mat file under the name you loaded it.
Chidiebere Ike
on 23 Oct 2018
Edited: Chidiebere Ike
on 23 Oct 2018
Thanks for the information. I appreciate. I tried this approach but noticed it didn't show all content but few. Also tried achieving this via octave still the same. The parameters I am looking forward to modifying isn't displayed compared to when I view the file from Matlab as it is. Any reason for this ?
Fangjun Jiang
on 23 Oct 2018
Please clarify the content of the .mat file, workspace data, or Simulink configuration/customization? MAT file can be used in many different ways these days. You might not use it in the right way.
Chidiebere Ike
on 23 Oct 2018
Thanks Rik. I appreciate
MOUSSAOUI FAOUZI
on 31 Dec 2021
Hello, all my Matlab files have been encrypted by ransomware online. Is there a way to recover and decrypt Matlab files? Thank you. moussaoui39fa@gmail.com
Accepted Answer
John D'Errico
on 23 Oct 2018
Edited: John D'Errico
on 23 Oct 2018
I believe the complete file specs for a .mat file are not published outside of The MathWorks. That means if you want to fully "decrypt" a .mat file, then change a variable, and save it back out, you have one good option - get a job at The MathWorks.
Of course even then, you still have a problem. Since the .mat files have changed format at times over the years with release changes, anything you did would be potentially version specific, and might not work with a different release.
So the only reliable solution to your problem is to not solve it as you wish. Instead, use load. Load the file, then modify the variables in question, and finally save it back out. This solution is easy and incredibly fast to implement, instead of the complex approach you seem to want to follow.
As far as your comment that you tried it, but not all content was shown, just means you may not understand how to properly use load, or perhaps are not using MATLAB properly. So it is difficult to help you there without seeing what confused you and what you indeed did try.
44 Comments
Chidiebere Ike
on 23 Oct 2018
Edited: Walter Roberson
on 23 Oct 2018
Lol. Thanks John. I did get your points clearly and I have been able to achieve the changes via your suggestion. However, I have issues with a code published on Matlab via this link https://www.mathworks.com/matlabcentral/fileexchange/38200-fast-non-local-mean-image-denoising-implementation. Corrections where made on the codes via the comments but I still have errors when I made the suggested corrections and applied the code in my proposed algorithm. The error reads below:
Index exceeds matrix dimensions.
Error in FAST_NLM_II (line 54)
SqDist =
Sd(PatchSizeHalf+WindowSizeHalf+1:Height+WindowSizeHalf+PatchSizeHalf,PatchSizeHalf+WindowSizeHalf+1:Width+WindowSizeHalf+PatchSizeHalf)...
% lower right corner
I will appreciate contributions.
Thank you
John D'Errico
on 23 Oct 2018
Use the debugger. It is always the way to solve such a problem. You can set it to interrupt processing at the point where an error occurs.
Check the size of the matrix involved. Then check the index. That index is not consistent with size of the matrix being indexed. How it got that way, I can only guess is due to a change that you made. So you would need to look at variables like PatchSizeHalf, etc. The debugger allows you to look at the values of each variable.
Chidiebere Ike
on 23 Oct 2018
Edited: Walter Roberson
on 23 Oct 2018
Thanks for your response. As suggested by a staff here that I break it down into smaller parts and I did.
whos Sd
[rows, columns] = size(Sd)
index1 = PatchSizeHalf+WindowSizeHalf+1
index2 = Height+WindowSizeHalf+PatchSizeHalf
index3 = PatchSizeHalf+WindowSizeHalf+1
index4 = Width+WindowSizeHalf+PatchSizeHalf
On running the above, it's observed that index2 is not bigger than rows, or index4 is not bigger than columns. I did tried to replace breakdown above in Line 56 on the original whose link I shared earlier. Below information was obtained to show the differences in index size
whos Sd
[rows, columns] = size(Sd)
index1 = PatchSizeHalf+WindowSizeHalf+1
index2 = Height+WindowSizeHalf+PatchSizeHalf
index3 = PatchSizeHalf+WindowSizeHalf+1
index4 = Width+WindowSizeHalf+PatchSizeHalf)
Name Size Bytes Class Attributes
Sd 522x522 2179872 double
rows =
522
columns =
522
index1 =
7
index2 =
518
index3 =
7
index4 =
518
Here is an error obtained after I had replaced the breakdown above in Line 56 of the original code.
Undefined function or variable 'SqDist'.
Error in FAST_NLM_II (line 64)
w = exp(-SqDist/(2*Sigma^2));
Quite frustrating at this point.
Thanks
Walter Roberson
on 23 Oct 2018
You appear to have missed
SqDist = Sd(index1:index2, index3:index4);
Perhaps the code is in a loop and the problem does not occur the first time, but does occur in some other iteration. You can add in
if rows < index2 || columns < index4
error('indices (%d:%d,%d:%d) out of range for Sd, which is (%d,%d)', index1, index2, index3, index4, rows, columns);
end
Chidiebere Ike
on 23 Oct 2018
Edited: Walter Roberson
on 23 Oct 2018
Thanks Walter. I did made corrections as advised. I replaced the said lines of code with the below:
[rows, columns] = size(Sd);
SqDist = Sd(index1:index2, index3:index4);
index1 = PatchSizeHalf+WindowSizeHalf+1;
index2 = Height+WindowSizeHalf+PatchSizeHalf;
index3 = PatchSizeHalf+WindowSizeHalf+1;
index4 = Width+WindowSizeHalf+PatchSizeHalf;
if rows < index2 || columns < index4
error('indices (%d:%d,%d:%d) out of range for Sd, which is (%d,%d)', index1, index2, index3, index4, rows, columns);
end
I obtained the error below, please guide me if I missed it.
Undefined function or variable 'index1'.
Error in FAST_NLM_IIcorrected (line 56)
SqDist = Sd(index1:index2, index3:index4);
Error in FNLM_NLM_II (line 175)
AO = FNLM_NLM_II(AO,9,15,0.15); % Filtered AO sub-bands
Fangjun Jiang
on 23 Oct 2018
the line SqDist = Sd(index1:index2, index3:index4); needs to be put after the lines where index1, ..., index4 are created.
Chidiebere Ike
on 23 Oct 2018
Edited: Walter Roberson
on 23 Oct 2018
Thanks Jiang for your response.
Here is the lines of code inputed:
%%NLM_II
% Get Image Info
[Height,Width] = size(NoisyImg);
% Initialize the denoised image
u = zeros(Height,Width);
% Initialize the weight max
M = u;
% Initialize the accumlated weights
Z = M;
% Pad noisy image to avoid Borader Issues
PaddedImg = padarray(NoisyImg,[PatchSizeHalf,PatchSizeHalf],'symmetric','both');
PaddedV = padarray(NoisyImg,[WindowSizeHalf,WindowSizeHalf],'symmetric','both');
% Main loop
for dx = -WindowSizeHalf:WindowSizeHalf
for dy = -WindowSizeHalf:WindowSizeHalf
if dx ~= 0 || dy ~= 0
% Compute the Integral Image
% Sd = integralImgSqDiff(PaddedImg,dx,dy);
Sd = integralImgSqDiff(PaddedV,dx,dy);
% Obtaine the Square difference for every pair of pixels
whos Sd
[rows, columns] = size(Sd);
index1 = PatchSizeHalf+WindowSizeHalf+1;
index2 = Height+WindowSizeHalf+PatchSizeHalf;
index3 = PatchSizeHalf+WindowSizeHalf+1;
index4 = Width+WindowSizeHalf+PatchSizeHalf;
SqDist = Sd(index1:index2, index3:index4);
if rows < index2 || columns < index4
error('indices (%d:%d,%d:%d) out of range for Sd, which is (%d,%d)', index1, index2, index3, index4, rows, columns);
end
end
Here is the error message:
Name Size Bytes Class Attributes
Sd 514x514 2113568 double
Index exceeds matrix dimensions.
Error in FAST_NLM_IIcorrected (line 61)
SqDist = Sd(index1:index2, index3:index4);
Error in FAST_NLM_II (line 175)
Walter Roberson
on 23 Oct 2018
Put the line
SqDist = Sd(index1:index2, index3:index4);
after the "if rows" test.
Chidiebere Ike
on 23 Oct 2018
Edited: Walter Roberson
on 23 Oct 2018
I did.
% Compute the Integral Image
% Sd = integralImgSqDiff(PaddedImg,dx,dy);
Sd = integralImgSqDiff(PaddedV,dx,dy);
% Obtaine the Square difference for every pair of pixels
whos Sd
[rows, columns] = size(Sd);
index1 = PatchSizeHalf+WindowSizeHalf+1;
index2 = Height+WindowSizeHalf+PatchSizeHalf;
index3 = PatchSizeHalf+WindowSizeHalf+1;
index4 = Width+WindowSizeHalf+PatchSizeHalf;
if rows < index2 || columns < index4
error('indices (%d:%d,%d:%d) out of range for Sd, which is (%d,%d)', index1, index2, index3, index4, rows, columns);
end
SqDist = Sd(index1:index2, index3:index4);
Error received:
In FNLM_LANR (line 190)
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
RCOND = NaN.
> In FNLM_LANR (line 190)
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
RCOND = NaN.
> In FNLM_LANR (line 190)
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
RCOND = NaN.
> In FNLM_LANR (line 190)
1/5 "Set5/baby_GT.bmp" [512 x 512]
Scale-Up GR.
Elapsed time is 1.430249 seconds.
Scale-Up ANR.
Elapsed time is 2.136054 seconds.
Scale-Up LANR.
Elapsed time is 1.420766 seconds.
Preprocessing, Iter 0 : PSNR = NaN; SSIM = NaN
Preprocessing, Iter 10 : PSNR = NaN; SSIM = NaN
Preprocessing, Iter 20 : PSNR = NaN; SSIM = NaN
Preprocessing, Iter 30 : PSNR = NaN; SSIM = NaN
No values of PSNR and SSIM was obtained.
Walter Roberson
on 23 Oct 2018
We do not seem to have the source for FNLM_LANR so we do not know what is near line 190.
Chidiebere Ike
on 23 Oct 2018
Ok. Please find attached file. Thanks for your time
Chidiebere Ike
on 23 Oct 2018
Yes, Exactly. Thats my base!
Walter Roberson
on 23 Oct 2018
Line 190 of your code is a mkdir() call. But line 182 is
conf.PPsTMM{i} = 1*Hi*inv(Lo'*Lo + 1e-5*diag(1./(vals(1:clustersz)).^11) )*Lo';
You should essentially never use inv(), it is not robust enough.
conf.PPsTMM{i} = 1*Hi*((Lo'*Lo + 1e-5*diag(1./(vals(1:clustersz)).^11)) \ Lo');
There is still a possibility that this will complain about singularity. I suggest you calculate
temp = (Lo'*Lo + 1e-5*diag(1./(vals(1:clustersz)).^11);
if size(temp,1) ~= size(temp,2)
error('Non-square temp, cannot have inverse');
end
if ~all(isfinite(temp(:)))
error('temp contains nan or inf, inverse would be nan');
end
rtemp = rank(temp);
if rtemp ~= size(temp,1)
error('temp is rank deficient, only rank %d instead of %d, no inverse', rtemp, size(temp,1));
end
conf.PPsTMM{i} = 1*Hi*(temp \ Lo');
Chidiebere Ike
on 23 Oct 2018
Edited: Chidiebere Ike
on 23 Oct 2018
Ops. Sorry for the initial message.
if true
% %%Each column in PPs corresponds to a atom in D_l
for i = 1:length(conf.points)
[vals idx] = sort(D(i,:), 'descend');
if (clustersz >= size(conf.dict_lores,2)/2)
conf.PPs{i} = conf.PP;
else
Lo = conf.dict_lores(:, idx(1:clustersz));
Hi = conf.dict_hires(:, idx(1:clustersz));
% conf.PPsTMM{i} = 1*Hi*inv(Lo'*Lo + 1e-5*diag(1./(vals(1:clustersz)).^11) \ Lo');
% conf.dict_middle(:,i) = conf.PPsTMM{i}*conf.dict_lores(:,i);
temp = (Lo'*Lo + 1e-5*diag(1./(vals(1:clustersz))).^11);
if size(temp,1) ~= size(temp,2)
error('Non-square temp, cannot have inverse');
end
if ~all(isfinite(temp(:)))
error('temp contains nan or inf, inverse would be nan');
end
rtemp = rank(temp);
if rtemp ~= size(temp,1)
error('temp is rank deficient, only rank %d instead of %d, no inverse', rtemp, size(temp,1));
end
conf.PPsTMM{i} = 1*Hi*(temp \ Lo');
conf.dict_middle(:,i) = conf.PPsTMM{i}*conf.dict_lores(:,i);
end
end
end
Error message obtained :
if true
% code Error using FNLM_LANR (line 189)
temp contains nan or inf, inverse would be nan
>>
end
Walter Roberson
on 24 Oct 2018
Is it possible that some of the D values are infinite?
Chidiebere Ike
on 24 Oct 2018
Most likely. The values are much in a 1024 x 1024 matrix. Please find attached. Thank you
Walter Roberson
on 24 Oct 2018
Please attach the matrix itself as a .mat
Chidiebere Ike
on 24 Oct 2018
The file size is large. 8Mb. How do I compress it? Thank you
Walter Roberson
on 24 Oct 2018
You could try zipping it. However as compression is already typically used, that might not help enough to fit within 5 megabytes. You could post a link to Google Drive or Dropbox.
Walter Roberson
on 24 Oct 2018
DD appears to be safely finite and invertible.
I guess I will need Lo and vals as of the time that the problem arises.
Chidiebere Ike
on 24 Oct 2018
Walter Roberson
on 24 Oct 2018
Your vals vector is entirely nan, so when you mix in 1/vals on the diagonal, everything comes out nan.
Chidiebere Ike
on 24 Oct 2018
Edited: Chidiebere Ike
on 24 Oct 2018
Ok. Pls How do I resolve this.. ? Thank you
Chidiebere Ike
on 24 Oct 2018
Edited: Walter Roberson
on 25 Oct 2018
I did run my codes successfully using the original code via this link:
But I observed that the original code compares only the lower right part of each patch, alongside the central pixel.
I do wish to compare the entire patch for a robust denoising; hence modification or corrections is required on the FAST_NLM_II file.
On executing the Corrections made via the comments gives several errors till date.
Thats my situation.
Thank you
Walter Roberson
on 25 Oct 2018
vals is derived from D. The only way for vals to have come out nan would be if D came out as nan. But when I asked you to attach D, you attached a matrix that was not nan in any location. However, the matrix you attached was named DD, which appears to be a different matrix.
So, something odd is happening.
Please execute the command
dbstop if naninf
and then run your code. You might see some routine tests in the code that should be ignored; if so, then command
dbcont
to continue going. Keep doing that until you find a nan or inf value being generated that you do not expect.
Chidiebere Ike
on 25 Oct 2018
Ok. Thanks. I will do as advised. However, D and DD is the same as I used it as different notations for different code samples...
Chidiebere Ike
on 25 Oct 2018
Edited: Walter Roberson
on 25 Oct 2018
Hello Mr. Walter. Upon executing the above mentioned codes, attached is what I obtained. However, I have attached some files.
1. FAST_NLM_II (Original code) ran successfully with my proposed algorithm with the attached D.mat and vals.mat file (No Nan values).
2. FAST_NLM with the corrections made so far on this thread, failed with NAN values.
I do intend to make the corrections on FAST_NLM as I observed that the FAST_NLM_II(original code) compares only the lower right part of each patch, alongside the central pixel.
I do wish to compare the entire patch for a robust denoising; hence modification or corrections is required on the FAST_NLM file.
I shared the above links so you could see the D and vals files for FAST_NLM_II which ran successfully. It's quite challenging to achieve this task but hopefully will.
I really appreciate your support..
Thanks
Walter Roberson
on 25 Oct 2018
I have loaded in the code. What arguments should I be passing to the routines?
Chidiebere Ike
on 25 Oct 2018
The input to the function is a Noisy or low-resolution image to efficiently denoise it. Thank you
Walter Roberson
on 26 Oct 2018
In order to reproduce your problem it would help if I had the same image you are working on, and you indicated the other three parameters such as the HalfWindow size.
Chidiebere Ike
on 26 Oct 2018
Edited: Walter Roberson
on 26 Oct 2018
OK Walter. Please find attached images that I use.
AO here is the Approximation sub-band to be filtered with the parameters below:
A1 = FAST_NLM_II(AO,9,15,0.15);
PatchSizeHalf = 9
WindowSizeHalf = 15
Sigma = 0.15
Detailed sub-bands (H1,H2,H3) are filtered with the same parameters below:
D1 = FAST_NLM_II(H1,3,3,0.15);
D2 = FAST_NLM_II(H2,3,3,0.15);
D3 = FAST_NLM_II(H3,3,3,0.15);
PatchSizeHalf = 3
WindowSizeHalf = 3
Sigma = 0.15
Thanks
Walter Roberson
on 26 Oct 2018
Edited: Walter Roberson
on 26 Oct 2018
I try things like
AO = rgb2gray(im2double(imread('baby_GT.bmp'))); A1 = FAST_NLM_II(AO,9,15,0.15);
but no error shows up.
I do not know what H1, H2, H3 are to be.
Walter Roberson
on 26 Oct 2018
You should post some code that takes is from input image name like 'baby_GT.bmp' to the point of reproducing the problem. It might only be a few lines, but we do not know what those lines are.
Chidiebere Ike
on 26 Oct 2018
Edited: Walter Roberson
on 26 Oct 2018
Here is the code I am working with that gives me the error when I tried to make the corrections Geert mentioned via the link below. Also Set5 in the input which contains the 5 pics I sent earlier:
If you find time, you can see the comments on that link. I do wish to compare the entire patch for a robust denoising rather than comparing only the lower right part of each patch, alongside the central pixel in FAST_NLM_II(original code) as published by Yue Wu
I need modifications of the function file to achieve the above.
This is my greatest desire on FAST_NLM_II function file. Please note, the errors I mentioned earlier shows up when I try to make corrections of Geert on the function files as stated in his comment via the link above. The original function file gives no error with my code.
Thank you
Walter Roberson
on 26 Oct 2018
I do not find run_comparison or run_comparisonRGB ?
Chidiebere Ike
on 26 Oct 2018
Edited: Walter Roberson
on 26 Oct 2018
Okay. Please find here.
Thanks
Walter Roberson
on 26 Oct 2018
I loaded in everything, made sure all the directories were on my path, made sure I was invoking your new Demo_LANR instead of the one from the google drive (the google drive one does not invoke FAST_LANR* at all), made sure I copied over the files from Set5 of the google drive.
And... I am not having any difficulty. No error messages.
The only warning messages have to do with the addpath() that are not needed anyhow because I had already added the appropriate directories to the path.
Chidiebere Ike
on 26 Oct 2018
Can you please share your own code from your end? Both the main code and function file FAST_NLM_II you used.. So I can compare with mine. And try to figure what went wrong and where. I appreciate your effort and guide. Thanks so much
Walter Roberson
on 26 Oct 2018
I did not make any changes to your code. I installed all of the code, used pathtool to ensure that the various directories were on the path, copied Set5 into place; and executed. Along the way I did need to cd into a couple of directories and "make" to compile some of the tools because I am on Mac and the precompiled versions happened to be for Windows (this showed up as clear missing function messages, not as nan showing up.)
Chidiebere Ike
on 26 Oct 2018
Ok. Thanks so much. I really appreciate your time.
Chidiebere Ike
on 27 Oct 2018
Edited: Walter Roberson
on 27 Oct 2018
Hello Mr. Walter. I tried to create a function file for Demo_LANR_NLM for the code via https://github.com/junjun-jiang/LANR-NLM/blob/master/Demo_LANR_NLM.m but got stocked at a point. How do I achieve this successfully. I will appreciate if you could help or guide me create the Demo_LANR_NLM file in a function file. I have attached what I did so far.
Thanks
Walter Roberson
on 27 Oct 2018
You have
for i = 1:numel(midres)
features = collect(conf, {midres{i}}, conf.upsample_factor, conf.filters);
features = double(features);
end
You do not output features anywhere, so there would not appear to be any point in calculating them.
You are overwriting all of the variable features each round of the loop.
Chidiebere Ike
on 27 Oct 2018
Edited: Chidiebere Ike
on 27 Oct 2018
The attachment I made was what I did so far.
Please please guide me through this sir to achieve this. I wish to compare this Demo_LANR_NLM method alongside other methods with my proposed method and will be good to have DEMO_LANR_NLM in function file like I had others such as BICUBIC, Global Regressor, ANR, LANR etc on "methods" folder.
What I always do is to run the Demo_LANR_NLM code separately to obtain its PSNR and SSIM values and images quality… And run my proposed code separately as well to compare both.
So I felt it will be better to run all at once in my code. Just like the Demo_LANR_NLM code had bicubic, ScSR, ANR, GR and LANR etc in its list of the methods to be compared.
Thats all.
Guide me sir
More Answers (1)
Walter Roberson
on 23 Oct 2018
https://www.mathworks.com/matlabcentral/answers/15521-matlab-function-save-and-v7-3
Mat files are not encrypted. They are data files, many of the entries are compressed. See the link for Malcolm's utilities.
2 Comments
Fangjun Jiang
on 23 Oct 2018
The OP's question and comments are misleading. They sounded complicated but it turned out to be not knowing a simple command. Now the Q&A are completely off topic.
Chidiebere Ike
on 23 Oct 2018
Edited: Chidiebere Ike
on 23 Oct 2018
I am sorry about that Jiang. My first issue has been solved. Then I presented another here. Here is the link https://www.mathworks.com/matlabcentral/answers/425033-how-do-i-solve-this-error-index-exceeds-matrix-dimensions#comment_625175..
Any contribution will be appreciated.
Thank you so much
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Tags
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 (한국어)