MATLAB Answers

0

combine binary image

I have a code like this
%%function of checkbox: cJalan -------
jalan = get(handles.aJalan, 'Userdata');
[p, l] = size(jalan);
nil = get(handles.cJalan, 'Value');
if nil == 1
jalan;
setappdata(handles.cJalan, 'jalan_', jalan);
else
jalan = zeros(p,l, 'uint8');
setappdata(handles.cJalan, 'jalan_', jalan);
% handles.jalan = jalan;
end
% -----------------------------------------
%%function of checkbox: cSungai
function cSungai_Callback(hObject, eventdata, handles)
sungai = get(handles.aSungai, 'Userdata');
[p, l] = size(sungai);
nil = get(handles.cSungai, 'Value');
if nil == 1
sungai;
setappdata(handles.cSungai, 'sungai_', sungai);
else
sungai = zeros(p,l, 'uint8');
setappdata(handles.cSungai, 'sungai_', sungai);
end
% ---------------------------------------
and 3 checkboxs other. i used them to combine their object, the object of 'cJalan' is 'jalan', and object of 'cSungai' is 'sungai'
each object will be called to combine the objects into a frame.. and i try to used this code to combine them..
to illustrate the problem, u can look this picture http://www.flickr.com/photos/77405333@N03/6791139372/
j = getappdata(handles.cJalan, 'jalan_');
s = getappdata(handles.cSungai, 'sungai_');
l = getappdata(handles.cLapangan, 'lapangan_');
sa = getappdata(handles.cSawah, 'sawah_');
g = getappdata(handles.cGedung, 'gedung_');
gabung = j|s|l|sa|g;
l, sa and g have same code with 2 checkbox others. in this case, 3 checkbox is unchecked.
how I can combine them, although not all axes fully.. do you have any example code with this problem..?? thanks..

  0 Comments

Sign in to comment.

1 Answer

Answer by Chandra Kurniawan on 9 Mar 2012
 Accepted Answer

Hi,
I think, first you should check whether the data is empty or not using for-loop.
hnd = {handles.cJalan,handles.cSungai,handles.cLapangan,handles.cSawah,handles.cGedung};
var = {'jalan_','sungai_','lapangan_','sawah_','gedung_'};
% I assume that the images have 256x256 dimension
gabung = logical(zeros([256 256]));
for x = 1 : 5
v{x} = getappdata(hnd{x},var{x});
if ~isempty(v{x})
gabung = gabung | v{x};
end
end
imshow(gabung);
I hope this works!

  2 Comments

Rahma Yeni on 10 Mar 2012
thank you Chandra... Now, my picture can be combined ... your code really helped me,, :) :) ^^ thanks.. I want to ask one more... how i can make history like in Photoshop..??? Where, when I choose a process, the process will be included in a list .. Then if I choose the second process, the second process will be listed under the first process.. i illustrate it like this
http://www.flickr.com/photos/rye_ni/6822456324/in/photostream
i hope, you can help me again... thanks before.. :)
Please see your question page :
http://www.mathworks.com/matlabcentral/answers/31729-make-history

Sign in to comment.