مسا عدة في كود


(system) #1

مرحبا
بدي مساعده على برمجية الماتلاب …
بدي اعمل GUIوفيه مجموعة ازرار push buttons
واحد بيعمل load لصورة
وواحد بيعمل salt & pepper noise
وواحد بيعمل filter كل واحد داخل push button
بدي كود median filter
وmax min filters
و harmonic mean filter
بتقدروا تساعدوني رجاء
الموضوع مهم جدا جدا جدا
وشكرا


(Ahmed) #2

[CENTER]مرحبا

قمت بعمل تطبيق بسيط للمطلوب

ينقصه الفلتر الاخير
harmonic mean filter
قم ببرمجته بنفسك كي تفهم البقية

الكود


%   Main Fucntion==========================================================
function SimpleFilter
clear all;
close all;
clc;
% UIControls Creation
h.figure=figure('Name','SimpleFilter','Position',[400 300 1000 400],'Toolbar','none','MenuBar','none','NumberTitle','off','Resize','off');
 
h.iPanel=uipanel('Position',[0.01 .2 .32 .78],'Title','Original Image','TitlePosition','centertop');
h.nPanel=uipanel('Position',[0.34 .2 .32 .78],'Title','Noised Image','TitlePosition','centertop');
h.fPanel=uipanel('Position',[0.67 .2 .32 .78],'Title','Filtered Image','TitlePosition','centertop');

h.iAxes=axes('Parent',h.iPanel,'Position',[0 0 1 1],'Visible','off','XTick',[],'YTick',[]);
h.nAxes=axes('Parent',h.nPanel,'Position',[0 0 1 1],'Visible','off','XTick',[],'YTick',[]);
h.fAxes=axes('Parent',h.fPanel,'Position',[0 0 1 1],'Visible','off','XTick',[],'YTick',[]);

h.iGroup=uibuttongroup('Position',[.01 .01 .32 .16]);
h.nGroup=uibuttongroup('Position',[.34 .01 .32 .16]);
h.fGroup=uibuttongroup('Position',[.67 .01 .32 .16]);

h.lButton=uicontrol('Style','pushbutton','Parent',h.iGroup,'FontUnits','normalized','Units','normalized','Position',[.2 .15 .6 .7],'String','Load Image');

h.nButton=uicontrol('Style','pushbutton','enable','off','Parent',h.nGroup,'Units','normalized','Position',[.1 .15 .3 .7],'String','Add Noise');
h.nSlider=uicontrol('Style','slider','enable','off','Parent',h.nGroup,'Units','normalized','Position',[.5 .15 .4 .3],'Max',100,'Min',1,'Value',2);
h.nLabel=uicontrol('Style','text','Parent',h.nGroup,'Units','normalized','Position',[.5 .5 .4 .3],'String','Noise Density = 2%');

h.mfButton=uicontrol('Style','pushbutton','enable','off','Parent',h.fGroup,'Units','normalized','Position',[.04 .25 .2 .5],'String','Median');
h.nfButton=uicontrol('Style','pushbutton','enable','off','Parent',h.fGroup,'Units','normalized','Position',[.28 .25 .2 .5],'String','Min');
h.xfButton=uicontrol('Style','pushbutton','enable','off','Parent',h.fGroup,'Units','normalized','Position',[.52 .25 .2 .5],'String','Max');
h.hfButton=uicontrol('Style','pushbutton','enable','off','Parent',h.fGroup,'Units','normalized','Position',[.76 .25 .2 .5],'String','Harmonic');

set(h.lButton,'callback',{@LoadImage,h});
end
%   Load Button Fucntion=================================================== 
function h=LoadImage(hObject,eventdata,h)
    [h.ImageName,h.ImagePath,h.FilterIndex] =uigetfile(...
                           {'*.jpg;*.tif;*.png;*.gif','All Image Files';...
                            '*.*','All Files' },...
                            'Select the image');
if ~isequal(h.ImageName,0)
    if isequal(h.FilterIndex,2)
        msgbox('Invalid Image File','Error','error')
    else
        h.image=imread(fullfile(h.ImagePath, h.ImageName));
        cla(h.nAxes,'reset');
        set(h.nAxes,'Visible','off');
        cla(h.fAxes,'reset');
        set(h.fAxes,'Visible','off');
        set(h.mfButton,'enable','off');
        set(h.nfButton,'enable','off');
        set(h.xfButton,'enable','off');
        
        set(h.iAxes,'Visible','on');
        imshow(h.image, 'Parent', h.iAxes);
        set(h.nButton,'enable','on','callback',{@AddNoise,h});
        set(h.nSlider,'enable','on','callback',{@NoiseDensity,h});
    end
end
guidata(hObject,h);
end
%   Noise Button Fucntion==================================================
function h= AddNoise(hObject,eventdata,h)
h.sValue=get(h.nSlider,'Value');

h.noisedImage=imnoise(h.image,'salt & pepper',h.sValue/100);
set(h.nAxes,'Visible','on');
imshow(h.noisedImage, 'Parent', h.nAxes);
set(h.mfButton,'enable','on','callback',{@MedianFilter,h});
set(h.nfButton,'enable','on','callback',{@MinFilter,h});
set(h.xfButton,'enable','on','callback',{@MaxFilter,h});

guidata(hObject, h);
end
%   Noise Density Slider Fucntion==========================================
function h= NoiseDensity(hObject,eventdata,h)
h.sValue=get(hObject,'Value');
set(h.nLabel,'String',strcat('Noise Density = ',num2str(h.sValue),'%'));

h.noisedImage=imnoise(h.image,'salt & pepper',h.sValue/100);
set(h.nAxes,'Visible','on');
imshow(h.noisedImage, 'Parent', h.nAxes);
set(h.mfButton,'enable','on','callback',{@MedianFilter,h});
set(h.nfButton,'enable','on','callback',{@MinFilter,h});
set(h.xfButton,'enable','on','callback',{@MaxFilter,h});

guidata(hObject, h);
end
%   Median Filter Button Fucntion==========================================
function h= MedianFilter(hObject,eventdata,h)
[m n b]=size(h.noisedImage);
if b==1
    h.filtredImage = medfilt2(h.noisedImage);
else
    Red=medfilt2(h.noisedImage(:,:,1));
    Green=medfilt2(h.noisedImage(:,:,2));
    Blue=medfilt2(h.noisedImage(:,:,3));
    h.filtredImage = cat(3,Red,Green,Blue);
end
imshow(h.filtredImage, 'Parent', h.fAxes);
guidata(hObject, h);
end
%   Min Filter Button Fucntion=============================================
function h= MinFilter(hObject,eventdata,h)
[m n b]=size(h.noisedImage);
if b==1
    h.filtredImage = ordfilt2(h.noisedImage,1,ones(3,3));
else
    Red=ordfilt2(h.noisedImage(:,:,1),1,ones(3,3));
    Green=ordfilt2(h.noisedImage(:,:,2),1,ones(3,3));
    Blue=ordfilt2(h.noisedImage(:,:,3),1,ones(3,3));
    h.filtredImage = cat(3,Red,Green,Blue);
end
imshow(h.filtredImage, 'Parent', h.fAxes);
guidata(hObject, h);
end
%   Max Filter Button Fucntion=============================================
function h= MaxFilter(hObject,eventdata,h)
[m n b]=size(h.noisedImage);
if b==1
    h.filtredImage = ordfilt2(h.noisedImage,9,ones(3,3));
else
    Red=ordfilt2(h.noisedImage(:,:,1),9,ones(3,3));
    Green=ordfilt2(h.noisedImage(:,:,2),9,ones(3,3));
    Blue=ordfilt2(h.noisedImage(:,:,3),9,ones(3,3));
    h.filtredImage = cat(3,Red,Green,Blue);
end
imshow(h.filtredImage, 'Parent', h.fAxes);
guidata(hObject, h);
end

امثلة عن الاستخدام

[/center]


(system) #3

شكرا كثير على المساعدة
لكن انا كنت عامله GUI باستخدام الguide
وشغال عندي كل شي الا الفلاتر
اذا ممكن تساعدوني بالفلاتر بناء على الشغل الي انا عملته بكون شاكره كثير
هاي الكودات الي انا استخدمتهم من اول والGUI الي عملتها صورة بالمرفقات

Load Image ..
global im im2 
[path ,user_cance]=imgetfile();
if user_cance 
    msgbox(sprintf('Error'),'Error','Error');
    return 
end
im= imread(path);
im=im2double(im);%converts to double 
im2=im; %for backup process
axes (handles.iAxes);
 imshow(im);

 Gaussian Noise ..
global im
im2=imnoise(im,'gaussian',0.3);
axes (handles.nAxes);
imshow(im2);

Salt and Pepper Noise ..
global im
im2= imnoise(im,'salt & pepper',0.02);
axes (handles.nAxes);
imshow(im2);


Speckle Noise ..
global im
im2= imnoise(im,'speckle',0.4);
axes (handles.nAxes);
imshow(im2);



SAVE the Image ..
[arq,dir] = uiputfile('*.jpg','Output Files');
fileName=fullfile(dir,arq);
f=getframe(handles.nAxes);
[x,map]=frame2im(f);
imwrite(x,fileName,'jpg');



Reset the Image to Original ..
global im2
axes (handles.nAxes);
imshow(im2);