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

Stephen23
Stephen23 2019년 2월 21일
What sizes are z and r ?
Walter Roberson
Walter Roberson 2019년 2월 21일
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
Quan Ly Duong 2019년 2월 21일
i forgot to remove it out, sorry
Quan Ly Duong
Quan Ly Duong 2019년 2월 21일
z size = anhmo
and r size = double(k - mod(k,2)) ??

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2019년 4월 5일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2019년 2월 21일

답변:

2019년 4월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by