Saturday, July 18, 2020

Code:多项参考

  1. [Matlab]删除XLS文件特定Sheet或空白Sheet(默认Sheet);
  2. [SPEI_SPI]计算栅格站点;
  3. [Matlab]统计知网关键词词频;
  4. [Matlab]
  5. 1
    2
    3
    4
    5
    % Read Image
    [image, geo]=readgeoraster(imgpath);
    info=georasterinfo(imgpath);
    % Save Image
    geotiffwrite('newimg.tif', image, geo); 
    
    % read a geo-referenced image 
    [image, geo]=readgeoraster(filepath);
    
    try
        info=geotiffinfo(filepath);
    catch
        info=georasterinfo(filepath);
    end
    
    % write a geo-referenced image 
    try
        geotiffwrite(otpath, uint8(class_imag), geo);
    catch
        strcmd=['gdalinfo ', filepath];
        [~, cmdout]=system(strcmd);
        epsg=extractBetween(cmdout, "EPSG:"," got from GeoTIFF keys");
        epsg=epsg{1};
        % geotiffwrite(otpath, uint8(class_imag), geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
        geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg]);
    end
    
    1
    geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg], 'TiffType', 'bigtiff');
    
    1
    geotiffwrite('m2.tif', image, geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
    
  6. [Matlab] A powerful toolbox for exporting images, refer to the online documentation for usage instructions; to save images and prevent accidents, use export_fig('exportfig_painters.png', '-png', '-painters', '-r300');. When the image contains Chinese characters, refer to this code snippet: export_fig([name,'.png'], '-png', '-r400','-q300');.
  7. [Matlab] Get the parent folder path
  8.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    %==========================================================================================================================
    % Gets the folder one level up.  If startingFolder is a filename with an extension it gets the containing folder and the child folder is null.
    % Returns null for both if the folder does not exist, and it's not a filename either.
    function [parentFolder, childFolder] = GetParentFolder(startingFolder)
    parentFolder = []; % Initialize
    childFolder = []; 
    try
    	if isfolder(startingFolder)
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		% Need to append extension for rare cases where deepest folder has a dot in the name.
    		childFolder = [childFolder, ext];
    	elseif isfile(startingFolder)
    		% It's a filename, not a folder.  Need to change otherwise childFolder will be returned as the base file name.
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		childFolder = []; % No child folder since it's a filename, not a folder name.
    	end
    catch ME
    	message = sprintf('Error in GetParentFolder():\n%s', ME.message);
    	uiwait(msgbox(message));
    end
    return; % from GetParentFolder
    end
    
  9. [Matlab]Export text on a text file.
  10. 1
    2
    3
    4
    fid=fopen(txtpath, 'w', 'n', 'US-ASCII');
    fprintf(fid, '%s\r\n', num2str(value));
    fclose(fid);
    fclose('all');
    
  11. [Matlab]Enhance RGB Image Code.
  12.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    function enhan_image=GenenhanImage(filepath)
    %  https://www.mathworks.com/matlabcentral/fileexchange/64932-files-for-demystifying-deep-learning-semantic-segmentation-and-deployment?s_tid=srchtitle
         % Load the images located in the above path using imageDatstore - ML Function
        imds = imageDatastore(filepath);
        pic_num = 1;
        I_raw = readimage(imds, pic_num);
    
        enhan_image= histeq(uint8(I_raw)); 
    
    end