Utilities (MATLAB)--visualizes Filters (visual filter)

Source: Internet
Author: User

 function [H, array] = display_network(A, Opt_normalize, Opt_graycolor, cols, Opt_ Colmajor) % This function visualizes filters in matrix A. Each column of a is a% filter. We'll reshape each column into a square image and visualizes% on each cell of the visualization panel.% All other parameters is optional, usually you does not need to worry% about it.% Opt_normalize:whether We need to normalize , the filter so, all of% them can have similar contrast. Default value is true.% Opt_graycolor:whether We use gray as the heat map. Default is true.% cols:how Many columns is there in the display. Default value is the% SquareRoot of the number of columns in A.% opt_colmajor:you can switch convention to row major for A. in that% case, per row of a is a filter. Default value is false.Warning off allif~exist (' Opt_normalize ',' var ') ||IsEmpty(opt_normalize) opt_normalize= true;Endif~exist (' Opt_graycolor ',' var ') ||IsEmpty(Opt_graycolor) opt_graycolor= true;Endif~exist (' Opt_colmajor ',' var ') ||IsEmpty(opt_colmajor) Opt_colmajor = false;EndDisplay (opt_normalize)% RescaleA = A-mean (A (:));ifOpt_graycolor, ColorMap (gray);End% compute rows, cols[L, M]=size(A); sz=sqrt(L); buf=1;if~exist (' cols ',' var ')if  Floor(sqrt(M)) ^2~= M n=Ceil(sqrt(M)); while MoD(M, N) ~=0&& n<1.2*sqrt(M), n=n+1;Endm=Ceil(m/n);Elsen=sqrt(M); M=n;EndElsen = cols; m =Ceil(m/n);Endarray=-ones(buf+m* (SZ+BUF), buf+n* (SZ+BUF));if~opt_graycolor array =0.1. * Array;Endif~opt_colmajor k=1; for I=1: M for J=1: NifK>m,Continue;EndClim=max (ABS(A (:, k)));ifOpt_normalize Array (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/clim;ElseArray (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/max (ABS(A (:)));Endk=k+1;End    EndElsek=1; for J=1: N for I=1: MifK>m,Continue;EndClim=max (ABS(A (:, k)));ifOpt_normalize Array (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz)/clim;ElseArray (buf+ (I-1) * (SZ+BUF) + (1: SZ), buf+ (J-1) * (SZ+BUF) + (1: SZ)) =Reshape(A (:, K), Sz,sz);Endk=k+1;End    EndEndifOpt_graycolor H=imagesc (Array,' Erasemode ',' None ',[-1 1]);ElseH=imagesc (Array,' Erasemode ',' None ',[-1 1]);EndAxis Image offdrawnow;warning on all

Utilities (MATLAB)--visualizes Filters (visual filter)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.