Matrix dimensions must agree
Afficher commentaires plus anciens
I tried to make a gui about LSB watermarking
% --- Executes on button press in btnChonAnhGoc2.
function btnChonAnhGoc2_Callback(hObject, eventdata, handles)
% hObject handle to btnChonAnhGoc2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[tenAnh, duongDanAnh] = uigetfile( ...
{'*.jpg;*.png;*.bmp;*.jpeg;*.tif', 'All MATLAB Files (*.jpg, *.png, *.bmp, *.jpeg, *.tif)'; ...
'*.*', 'All Files (*.*)'}, ...
'Chon Hinh Anh De Mo');
full = strcat(duongDanAnh, tenAnh);
global anhGoc2;
anhGoc2 = imread(full);
anhGoc2=imresize(anhGoc2,[512,512]);
axes(handles.axes1);
imshow(anhGoc2);
% --- Executes on button press in btnChonWatermark2.
function btnChonWatermark2_Callback(hObject, eventdata, handles)
% hObject handle to btnChonWatermark2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[tenAnh, duongDanAnh] = uigetfile( ...
{'*.jpg;*.png;*.bmp;*.jpeg;*.tif', 'All MATLAB Files (*.jpg, *.png, *.bmp, *.jpeg, *.tif)'; ...
'*.*', 'All Files (*.*)'}, ...
'Chon Hinh Anh De Mo');
f = strcat(duongDanAnh, tenAnh);
global anhmo;
anhmo = imread(f);
anhmo=imresize(anhmo,[512,512]);
axes(handles.axes2);
imshow(anhmo);
% --- Executes on button press in btnXuatketqua2.
function btnXuatketqua2_Callback(hObject, eventdata, handles)
% hObject handle to btnXuatketqua2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global anhGoc2;
global anhmo;
k= rgb2gray(anhGoc2);
z= imbinarize(anhmo);
z= double(z);
r= double(k - mod(k,2));
l= uint8(z + r);
axes(handles.axes3);
imshow(l)
when i start the code i got Matrix dimensions must agree error at line l= uint8(z + r);
Can anyone know how to fix it?
4 commentaires
Stephen23
le 21 Fév 2019
What sizes are z and r ?
Walter Roberson
le 21 Fév 2019
You resized one image to 512x512 but not the other one .
What is the purpose of testing whether ndims is not 0?
Quan Ly Duong
le 21 Fév 2019
Quan Ly Duong
le 21 Fév 2019
Réponses (1)
Cris LaPierre
le 5 Avr 2019
1 vote
What version of MATLAB are you using? If pre 16b, the issue might be the 3rd dimension.
k= rgb2gray(anhGoc2); makes k a 512x512x1 matrix. As far as I can tell, anhmo remains a 512x512x3, which would cause a matrix dimension error when adding z and r in a version of MATLAB that does not support implicit expansion.
The simplest fix is probably to turn anhmo into a grayscale image as well.
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!