humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

remove_noise

remove_noise($inpath,$outpath,$kernel_size=3); - убрать шум с картинки доступна с версии 7.0.56

Функция на вход принимает параметры:

  • $inpath – путь к исходной картинки (может быть относительным)
  • $outpath – путь к новой картинке (может быть относительным)
  • $kernel_size – размер ядра Гауса

    После отработки функция возвращает результат своей работы в скрипт :
  • true – успешно выполнили (boolean)
  • false – операция не произведена (boolean)

    Пример использования
    <?php
    // Scenario: Remove noise from an image using Gaussian blur
    $xhe_host = "localhost:7010";
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // Path to the source image
    $sourceImagePath = "images/noisy_image.png";
    
    // Path for the resulting noise-removed image
    $denoisedImagePath = "images/denoised_image.png";
    
    // Make sure the source image file exists
    if (file_exists($sourceImagePath)) {
        echo "Source image found at: " . $sourceImagePath . "\n";
        
        // Remove noise from the image using default kernel size (3)
        echo "Removing noise from image with default kernel size (3)...\n";
        $result = DOM::$image->remove_noise($sourceImagePath, $denoisedImagePath);
        
        if ($result) {
            echo "Successfully removed noise from image\n";
            echo "Denoised image saved to: " . $denoisedImagePath . "\n";
            
            // Verify the new image was created
            if (file_exists($denoisedImagePath)) {
                echo "Denoised image file exists and has been saved\n";
                
                // Get file size of the new image
                $fileSize = filesize($denoisedImagePath);
                echo "Denoised image file size: " . $fileSize . " bytes\n";
            } else {
                echo "Warning: Denoised image file was not created\n";
            }
        } else {
            echo "Failed to remove noise from image\n";
        }
        
        // Example 2: Remove noise with a larger kernel size (5)
        $denoisedImagePath2 = "images/denoised_image_kernel5.png";
        $kernelSize = 5;
        
        echo "\nRemoving noise from image with kernel size (" . $kernelSize . ")...\n";
        $result2 = DOM::$image->remove_noise($sourceImagePath, $denoisedImagePath2, $kernelSize);
        
        if ($result2) {
            echo "Successfully removed noise from image with larger kernel\n";
            echo "Denoised image (kernel " . $kernelSize . ") saved to: " . $denoisedImagePath2 . "\n";
        } else {
            echo "Failed to remove noise from image with larger kernel\n";
        }
        
        // Example 3: Remove noise from a different image
        $sourceImagePath2 = "images/photo_with_noise.jpg";
        $denoisedImagePath3 = "images/photo_denoised.jpg";
        
        if (file_exists($sourceImagePath2)) {
            echo "\nRemoving noise from second image...\n";
            $result3 = DOM::$image->remove_noise($sourceImagePath2, $denoisedImagePath3);
            
            if ($result3) {
                echo "Successfully removed noise from second image\n";
                echo "Second denoised image saved to: " . $denoisedImagePath3 . "\n";
            } else {
                echo "Failed to remove noise from second image\n";
            }
        } else {
            echo "\nSecond source image not found at: " . $sourceImagePath2 . "\n";
        }
    } else {
        echo "Source image file not found at: " . $sourceImagePath . "\n";
        
        // For demonstration purposes
        echo "For this example to work, you would need an image file at: " . $sourceImagePath . "\n";
    }
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7024"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>image.xxxxxxxxx</font><hr>")
    
    # 1
    echo("1. Сгладим картинку : ");
    echo(image.remove_noise("test\\test.jpg","test\\test_no_noise.jpg"),"\n");
    
    # 2
    echo("2. Покажем результат : ");
    echo(app.shell_execute("open","test\\test_no_noise.jpg"));
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>image.add_image</font><hr>");
    							
    			// 1
    			echo("1. Сгладим картинку : ");
    			echo(image.remove_noise("test\\test.jpg","test\\test_no_noise.jpg")+"\n");
    
    			// 2
    			echo("2. Покажем результат : ");
    			echo(app.shell_execute("open","test\\test_no_noise.jpg"));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7024";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>image.add_image</font><hr>");
    
    // 1
    echo("1. Сгладим картинку : ");
    echo(image.remove_noise("test\\test.jpg","test\\test_no_noise.jpg")+"\n");
    
    // 2
    echo("2. Покажем результат : ");
    echo(app.shell_execute("open","test\\test_no_noise.jpg"));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Image    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.