Error opening file: Dot indexing is not supported for variables of this type. When opening a JPG image

2 ビュー (過去 30 日間)
Hi, I am very new in Matlab. Got this working code from my prof but I am facing some problems when running it on my machine (MacOS) that google haven't helped to solve. I am getting the following error:
imName: dataset/controlled/FB/QF-50/original-001-1012x1800.jpg
[dct_coef_hist.m]: jpeg_read() error: Attempt to execute SCRIPT jpeg_read as a function:
/Users/irene/Desktop/sharing-chains-reconstruction-main/src/jpegtbx_1.4/jpeg_read.m
Error opening file: Dot indexing is not supported for variables of this type.
Calling this function: (it fails in the first try-catch)
function histr = dct_coef_hist(imName)
% This function extracts histogram of DCT coefficients
% Input:
% coeff_arrays: 1x3 cell array of coefficients
% Nc: number of analyzed DCT coeff in each 8x8 blocks
% BT: the limit of histogram ==> number of bins = 2*BT + 1
channel = 1; % luminance channel
Nc = 9; % number of AC coefficients (zig zag scan)
BT = 20; % maximum bin value => number of bins = 2*BT+1
fprintf('imName: %s\n', imName);
jobj = [];
coef_arrays = [];
quant_table = [];
% --------------------error-----------------------------------------
try
% the original code had no try-catch so I implemented it to see more details about the error
jobj=jpeg_read(imName);
% it never gets here so the error must be in the line above (?!?)
coef_arrays = jobj.coef_arrays;
quant_table = jobj.quant_tables;
catch me
fprintf("[dct_coef_hist.m]: jpeg_read() error: %s\n", me.message);
end
% -----------------------end--------------------------------------
coef_arrays = jobj.coef_arrays;
quant_table = jobj.quant_tables;
[h,w] = size(coef_arrays{channel});
nblks = (floor(h/8)-1)*(floor(w/8)-1);
coefs = coef_arrays{1};
hist = zeros(Nc, (2*BT+1));
zigzag_inds = zigzag(reshape(1:64, [8 8]));
zigzag_inds = zigzag_inds(2:Nc+1);
for b = 0:nblks-1
i = 8*(floor(b / (floor(w/8)-1))) + 1;
j = 8*mod(b, (floor(w/8)-1)) + 1;
block = coefs(i:i+7, j:j+7);
block = block(zigzag_inds);
quant_values = quant_table{channel}(zigzag_inds);
for n = 1:Nc
v = block(n) * quant_values(n);
if v > BT
hist(n, end) = hist(n, end) + 1;
elseif v < -BT
hist(n, 1) = hist(n, 1) + 1;
else
hist(n, v+BT+1) = hist(n, v+BT+1) + 1;
end
end
end
hist = hist ./ nblks;
histr = reshape(hist, 1, []);
end
Here is also the code for jpeg_read.m
output = jpeg_read(imIn);
% JPEG_READ Read a JPEG file into a JPEG object struct
%
% JPEGOBJ = JPEG_READ(FILENAME) Returns a Matlab struct containing the
% contents of the JPEG file FILENAME, including JPEG header information,
% the quantization tables, Huffman tables, and the DCT coefficients.
%
% This software is based in part on the work of the Independent JPEG Group.
%
% See also JPEG_WRITE.
% Modified by Markos Zampoglou (markzampoglou@iti.gr), ITI-CERTH 2016.
% It now operates as a function
% Phil Sallee 6/2003
error("Mex routine jpeg_read.c not compiled\n");
I don't really understand what this last jpeg_read.m does... it is just calling jpeg_read(); which... is... what? is it a .c function? (I never get the error Mex routine jpeg_read.c not compiled so I am confused what is the point.
  10 件のコメント
dpb
dpb 2022 年 5 月 21 日
I "know nuthink!" about MacOS, sorry.
Make sure first you have mex set up -- try
mex -setup
to see if it finds the compiler successfully; often IME the automated search tool fails to find an installed and operating compiler because it makes too many assumptions about which releases are allowed and where it might be installed if anything is out of the "plain vanilla, accept all defaults" install.
If that succeeds in showing a C compiler is installed or you can run it with the "C" language parameter and it then finds one, then ensure you can compile/run one or two of the trivial examples -- timestwo.c and the like.
After that, you're ready to try to compile a real mex file in anger...
Good luck...

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 5 月 21 日
The library contains executables for Windows and Linux but not for Mac. You need to cd into the library and use mex to compile jpeg_read
  1 件のコメント
Bojan Poletan
Bojan Poletan 2022 年 5 月 25 日
編集済み: Bojan Poletan 2022 年 5 月 25 日
I wasn't really able to do that because I got many errors while compiling the C files. Missing includes, syntax errors and so on. So I contacted my prof and he provided me with a VPN access to the uni pc

サインインしてコメントする。


Bojan Poletan
Bojan Poletan 2022 年 5 月 25 日
My teacher provided me with a VPN acces to the university server they use for simulations so it should be fine. I don't think this answers to the question but I am not proceeding further in trying to solve it.

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by