Tuesday, April 28, 2020

Re-post กลับมาเขียนอีกครั้ง

ผมกลับมาใช้งาน MATLAB อีกครั้งรอบนี้ใช้เวอร์ชัน 2018a แต่เริ่มแบบเดิม ทดสอบการทำ GUI สำหรับเปิดภาพ แสดงเป็น RGB-, Red-, Green-, Blue- Grayscale เลือกแสดงที่ละแบบโดยใช้ฟังก์ชัน Off





ครั้งนี้ลองใช้ pushbutton แทน radio butoon การเขียนโปรแกรมควบคุมไม่ต่างกัน ใช้งานเช่นเดิม ลองดูตัวอย่างการใช้งานโปรแกรมนี้ดังภาพด้านล่าง









ตัวอย่าง source code ตรงไปตรงมา (ไม่ต้องหาความเป็นมืออาชีพด้านการเขียนโปรแกรมในบล็อก ผมนะครับ 555)

%สำหรับเปิดไฟล์รูปในโฟลเดอร์
function pushOpen_Callback(hObject, eventdata, handles)
% hObject    handle to pushOpen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[F,PathName,FilterIndex] = uigetfile({'*.*','All Files(*.*)'}, 'Select your File ');
input=strcat(PathName,F);
handles.RGBimage=importdata(input);
%====Display image on axesImage ======%
axes(handles.axesImage);
imshow(handles.RGBimage);%axis equal;axis tight;
hpixinfo = impixelinfo;
%zoom on;
%axis off;
%figure()
%imshow(handles.RGBimage);
guidata(hObject,handles);

% ส่วนควบคุม push button ที่ชื่อ tag ว่า pushRed
 function pushRed_Callback(hObject, eventdata, handles)
% hObject    handle to pushRed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

axes(handles.axesImage);
handles.RGBimage(:,:,2) = 0;
handles.RGBimage(:,:,3) = 0;
imshow(handles.RGBimage); title('Red-component image');axis equal;axis tight;axis off;impixelinfo;

off=[handles.pushRGB handles.pushGreen handles.pushGray handles.pushBlue];
Turn_Off(off);



ภาพที่นำมาทดสอบ นำมาจาก https://scholarlykitchen.sspnet.org/2019/11/06/born-digital-the-expanding-universe-of-research-content/  ไฟล์ต่างๆ ดาวโหลดได้จากที่นี่ >>> Download files

No comments:

Post a Comment