اطلاعیه

Collapse
No announcement yet.

function matlab

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    function matlab

    سلام
    من سه تا Mfile از اینترنت گرفتم در مورد مامو گرافی
    که در اول دو تا از mfiile ها از تابع function استفاده شده است.
    و هر چی اجرا می کنم error می دهد
    اگر می شود نحوه ی اجرای mfile هایی که دارای function هستند را به من بگویید.
    مرسی از لطفتون....

    *******************************
    clear all
    close all

    function [im1]=SegmentMammo(im)
    % [fname path]=uigetfile('*.pgm&#039
    % im=imread(strcat(path,fname));
    %figure,
    %subplot(1,3,1),title('ACTUAL&#039
    imshow(im);
    [clusters, result_image, clusterized_image] = kmeansclustering(im, 3);
    a=find(result_image<130);
    b=find(result_image>200);
    im1=im;
    im1(a)=0;
    im1(b)=0;
    %subplot(1,3,3),imshow(im1),title('FINAL SEGMENTED IMAGE'
    %subplot(1,3,2),imshow(result_image),title('S EGMENTATION PART&#039
    end
    end
    **************************************
    **************mammogreaphy-2******************
    clear all
    close all

    function [clusters, result_image, clusterized_image] = kmeansclustering(im, k)

    %histogram calculation
    img_hist = zeros(256,1);
    hist_value = zeros(256,1);

    for i=1:256
    img_hist(i)=sum(sum(im==(i-1)));
    end;
    for i=1:256
    hist_value(i)=i-1;
    end;
    %cluster initialization
    cluster = zeros(k,1);
    cluster_count = zeros(k,1);
    for i=1:k
    cluster(i)=uint8(rand*255);
    end;

    old = zeros(k,1);
    while (sum(sum(abs(old-cluster))) >k)
    old = cluster;
    closest_cluster = zeros(256,1);
    min_distance = uint8(zeros(256,1));
    min_distance = abs(hist_value-cluster(1));

    %calculate the minimum distance to a cluster
    for i=2:k
    min_distance =min(min_distance, abs(hist_value-cluster(i)));
    end;

    %calculate the closest cluster
    for i=1:k
    closest_cluster(min_distance==(abs(hist_value-cluster(i)))) = i;
    end;

    %calculate the cluster count
    for i=1:k
    cluster_count(i) = sum(img_hist .*(closest_cluster==i));
    end;


    for i=1:k
    if (cluster_count(i) == 0)
    cluster(i) = uint8(rand*255);
    else
    cluster(i) = uint8(sum(img_hist(closest_cluster==i).*hist_value (closest_cluster==i))/cluster_count(i));
    end;
    end;

    end;
    imresult=uint8(zeros(size(im)));
    for i=1:256
    imresult(im==(i-1))=cluster(closest_cluster(i));
    end;

    clustersresult=uint8(zeros(size(im)));
    for i=1:256
    clustersresult(im==(i-1))=closest_cluster(i);
    end;

    clusters = cluster;
    result_image = imresult;
    clusterized_image = clustersresult;
    end

    ****************************************
    *****************
    %% Read image
    clear
    f = im2double(imread('C:\Users\parto\Downloads\Fi g1006(a)(building).tif&#039);

    %% Display image
    imshow(f,[]);title('Original image'
    pause

    %% Edge Detection
    % [g, t] = edge(f, 'method', parameters);

    %% Sobel Edge Detection
    % automatic threshold
    [v, t] = edge(f, 'sobel' , 'vertical'
    imshow(v);title(sprintf('Sobel Edge Dectection [auto vertical t = %0.2f]',t));
    pause

    % manual threshold
    t = 0.15;
    v = edge(f, 'sobel', t, 'vertical'
    imshow(v);title(sprintf('Sobel Edge Dectection [manual vertical t = %0.2f]',t));
    pause

    % Sobel edge +45 degree
    w = [-2 -1 0; -1 0 1; 0 1 2];
    v = imfilter(f, w, 'replicate'
    t = 0.3*max(abs(v());
    v = v >= t;
    imshow(v);title(sprintf('Sobel Edge Dectection [manual +45 t = %0.2f]',t));
    pause

    % Sobel edge -45 degree
    w = [0 1 2; -1 0 1; -2 -1 0];
    v = imfilter(f, w, 'replicate'
    t = 0.3*max(abs(v());
    v = v >= t;
    imshow(v);title(sprintf('Sobel Edge Dectection [manual -45 t = %0.2f]',t));
    pause

    %% Other methods
    % Sobel
    v0 = edge(f, 'sobel'
    imshow(v0);title('Sobel Edge Dectection [auto]'
    pause

    % Prewitt
    v1 = edge(f, 'prewitt'
    imshow(v1);title('Prewitt Edge Dectection [auto]'
    pause

    % Roberts
    v2 = edge(f, 'roberts'
    imshow(v2);title('Roberts Edge Dectection [auto]'
    pause

    % Laplacian of Gaussian Method
    v3 = edge(f, 'log'
    imshow(v3);title('Laplacian of Gaussian Method [auto]'
    pause

    % Zero-cross
    v4 = edge(f, 'zerocross'
    imshow(v4);title('Zero-cross Method [auto]'
    pause

    % Canny
    v5 = edge(f, 'canny'
    imshow(v5);title('Canny Edge Dectection [auto]'
    pause

    subplot(231);imshow(v0);title('Sobel Edge Dectection [auto]'
    subplot(232);imshow(v1);title('Prewitt Edge Dectection [auto]'
    subplot(233);imshow(v2);title('Roberts Edge Dectection [auto]'
    subplot(234);imshow(v3);title('Laplacian of Gaussian Method [auto]'
    subplot(235);imshow(v4);title('Zero-cross Method [auto]'
    subplot(236);imshow(v5);title('Canny Edge Dectection [auto]'
    **************************************

    فان مع العسر يسرا
    پس (بدان که) مسلما با هر سختي دشواريي است.
    و ان ليس للانسن الا ما سعي
    واينکه براي انسان جز آنکه تلاش کرده چيزي نيست.

    #2
    پاسخ : function matlab

    نوشته اصلی توسط riant67
    سلام
    من سه تا Mfile از اینترنت گرفتم در مورد مامو گرافی
    که در اول دو تا از mfiile ها از تابع function استفاده شده است.
    و هر چی اجرا می کنم error می دهد
    اگر می شود نحوه ی اجرای mfile هایی که دارای function هستند را به من بگویید.
    مرسی از لطفتون....

    *******************************
    clear all
    close all

    function [im1]=SegmentMammo(im)
    % [fname path]=uigetfile('*.pgm&#039
    % im=imread(strcat(path,fname));
    %figure,
    %subplot(1,3,1),title('ACTUAL&#039
    imshow(im);
    [clusters, result_image, clusterized_image] = kmeansclustering(im, 3);
    a=find(result_image<130);
    b=find(result_image>200);
    im1=im;
    im1(a)=0;
    im1(b)=0;
    %subplot(1,3,3),imshow(im1),title('FINAL SEGMENTED IMAGE'
    %subplot(1,3,2),imshow(result_image),title('S EGMENTATION PART&#039
    end
    end
    **************************************
    **************mammogreaphy-2******************
    clear all
    close all

    function [clusters, result_image, clusterized_image] = kmeansclustering(im, k)

    %histogram calculation
    img_hist = zeros(256,1);
    hist_value = zeros(256,1);

    for i=1:256
    img_hist(i)=sum(sum(im==(i-1)));
    end;
    for i=1:256
    hist_value(i)=i-1;
    end;
    %cluster initialization
    cluster = zeros(k,1);
    cluster_count = zeros(k,1);
    for i=1:k
    cluster(i)=uint8(rand*255);
    end;

    old = zeros(k,1);
    while (sum(sum(abs(old-cluster))) >k)
    old = cluster;
    closest_cluster = zeros(256,1);
    min_distance = uint8(zeros(256,1));
    min_distance = abs(hist_value-cluster(1));

    %calculate the minimum distance to a cluster
    for i=2:k
    min_distance =min(min_distance, abs(hist_value-cluster(i)));
    end;

    %calculate the closest cluster
    for i=1:k
    closest_cluster(min_distance==(abs(hist_value-cluster(i)))) = i;
    end;

    %calculate the cluster count
    for i=1:k
    cluster_count(i) = sum(img_hist .*(closest_cluster==i));
    end;


    for i=1:k
    if (cluster_count(i) == 0)
    cluster(i) = uint8(rand*255);
    else
    cluster(i) = uint8(sum(img_hist(closest_cluster==i).*hist_value (closest_cluster==i))/cluster_count(i));
    end;
    end;

    end;
    imresult=uint8(zeros(size(im)));
    for i=1:256
    imresult(im==(i-1))=cluster(closest_cluster(i));
    end;

    clustersresult=uint8(zeros(size(im)));
    for i=1:256
    clustersresult(im==(i-1))=closest_cluster(i);
    end;

    clusters = cluster;
    result_image = imresult;
    clusterized_image = clustersresult;
    end

    ****************************************
    *****************
    %% Read image
    clear
    f = im2double(imread('C:\Users\parto\Downloads\Fi g1006(a)(building).tif&#039);

    %% Display image
    imshow(f,[]);title('Original image'
    pause

    %% Edge Detection
    % [g, t] = edge(f, 'method', parameters);

    %% Sobel Edge Detection
    % automatic threshold
    [v, t] = edge(f, 'sobel' , 'vertical'
    imshow(v);title(sprintf('Sobel Edge Dectection [auto vertical t = %0.2f]',t));
    pause

    % manual threshold
    t = 0.15;
    v = edge(f, 'sobel', t, 'vertical'
    imshow(v);title(sprintf('Sobel Edge Dectection [manual vertical t = %0.2f]',t));
    pause

    % Sobel edge +45 degree
    w = [-2 -1 0; -1 0 1; 0 1 2];
    v = imfilter(f, w, 'replicate'
    t = 0.3*max(abs(v());
    v = v >= t;
    imshow(v);title(sprintf('Sobel Edge Dectection [manual +45 t = %0.2f]',t));
    pause

    % Sobel edge -45 degree
    w = [0 1 2; -1 0 1; -2 -1 0];
    v = imfilter(f, w, 'replicate'
    t = 0.3*max(abs(v());
    v = v >= t;
    imshow(v);title(sprintf('Sobel Edge Dectection [manual -45 t = %0.2f]',t));
    pause

    %% Other methods
    % Sobel
    v0 = edge(f, 'sobel'
    imshow(v0);title('Sobel Edge Dectection [auto]'
    pause

    % Prewitt
    v1 = edge(f, 'prewitt'
    imshow(v1);title('Prewitt Edge Dectection [auto]'
    pause

    % Roberts
    v2 = edge(f, 'roberts'
    imshow(v2);title('Roberts Edge Dectection [auto]'
    pause

    % Laplacian of Gaussian Method
    v3 = edge(f, 'log'
    imshow(v3);title('Laplacian of Gaussian Method [auto]'
    pause

    % Zero-cross
    v4 = edge(f, 'zerocross'
    imshow(v4);title('Zero-cross Method [auto]'
    pause

    % Canny
    v5 = edge(f, 'canny'
    imshow(v5);title('Canny Edge Dectection [auto]'
    pause

    subplot(231);imshow(v0);title('Sobel Edge Dectection [auto]'
    subplot(232);imshow(v1);title('Prewitt Edge Dectection [auto]'
    subplot(233);imshow(v2);title('Roberts Edge Dectection [auto]'
    subplot(234);imshow(v3);title('Laplacian of Gaussian Method [auto]'
    subplot(235);imshow(v4);title('Zero-cross Method [auto]'
    subplot(236);imshow(v5);title('Canny Edge Dectection [auto]'
    **************************************
    دوست عزیز ای کاش قبل از ارسال پست برنامه را چپ به راست می گذاشتید.در هر صورت...
    چیزی که با این ظاهر بهم ریخته دستگیره من شد ، شما 2 تا تابع دارید و یک برنامه اصلی که من هر چقدر تو برنامه اصلی جست و جو کردم اصلاً ندیدم که جایی توابع نوشته شدتون صدا زده بشن.
    quand on veut,on peut...

    دیدگاه


      #3
      پاسخ : function matlab

      [left]سلام

      clear all
      close all

      function [im1]=SegmentMammo(im)
      % [fname path]=uigetfile('*.pgm&#039
      % im=imread(strcat(path,fname));
      %figure,
      %subplot(1,3,1),title('ACTUAL&#039
      imshow(im);
      [clusters, result_image, clusterized_image] = kmeansclustering(im, 3);
      a=find(result_image<130);
      b=find(result_image>200);
      im1=im;
      im1(a)=0;
      im1(b)=0;
      %subplot(1,3,3),imshow(im1),title('FINAL SEGMENTED IMAGE'
      %subplot(1,3,2),imshow(result_image),title('S EGMENTATION PART&#039
      end
      end
      **************************************
      clear all
      close all

      function [clusters, result_image, clusterized_image] = kmeansclustering(im, k)

      %histogram calculation
      img_hist = zeros(256,1);
      hist_value = zeros(256,1);

      for i=1:256
      img_hist(i)=sum(sum(im==(i-1)));
      end;
      for i=1:256
      hist_value(i)=i-1;
      end;
      %cluster initialization
      cluster = zeros(k,1);
      cluster_count = zeros(k,1);
      for i=1:k
      cluster(i)=uint8(rand*255);
      end;

      old = zeros(k,1);
      while (sum(sum(abs(old-cluster))) >k)
      old = cluster;
      closest_cluster = zeros(256,1);
      min_distance = uint8(zeros(256,1));
      min_distance = abs(hist_value-cluster(1));

      %calculate the minimum distance to a cluster
      for i=2:k
      min_distance =min(min_distance, abs(hist_value-cluster(i)));
      end;

      %calculate the closest cluster
      for i=1:k
      closest_cluster(min_distance==(abs(hist_value-cluster(i)))) = i;
      end;

      %calculate the cluster count
      for i=1:k
      cluster_count(i) = sum(img_hist .*(closest_cluster==i));
      end;


      for i=1:k
      if (cluster_count(i) == 0)
      cluster(i) = uint8(rand*255);
      else
      cluster(i) = uint8(sum(img_hist(closest_cluster==i).*hist_value (closest_cluster==i))/cluster_count(i));
      end;
      end;

      end;
      imresult=uint8(zeros(size(im)));
      for i=1:256
      imresult(im==(i-1))=cluster(closest_cluster(i));
      end;

      clustersresult=uint8(zeros(size(im)));
      for i=1:256
      clustersresult(im==(i-1))=closest_cluster(i);
      end;

      clusters = cluster;
      result_image = imresult;
      clusterized_image = clustersresult;
      end
      *****************************************
      سلام ممنون ار توضیحتون
      ام فایل سوم لبه یابی است....ما با دو تا ام فایل اول کارداریم....
      براتون ام فایل ها رو درست کردم بی زحمت یه نگاه دیگه بندازید.





















      فان مع العسر يسرا
      پس (بدان که) مسلما با هر سختي دشواريي است.
      و ان ليس للانسن الا ما سعي
      واينکه براي انسان جز آنکه تلاش کرده چيزي نيست.

      دیدگاه

      لطفا صبر کنید...
      X