class_docstr: Module extracting line segments from junctions and line heatmaps.
  
  Args:
      detect_thresh: The probability threshold for mean activation (0. ~ 1.)
      num_samples: Number of sampling locations along the line segments.
      inlier_thresh: The min inlier ratio to satisfy (0. ~ 1.) => 0. means no threshold.
      heatmap_low_thresh: The lowest threshold for the pixel to be considered as candidate in junction recovery.
      heatmap_high_thresh: The higher threshold for NMS in junction recovery.
      max_local_patch_radius: The max patch to be considered in local maximum search.
      lambda_radius: The lambda factor in linear local maximum search formulation
      use_candidate_suppression: Apply candidate suppression to break long segments into short sub-segments.
      nms_dist_tolerance: The distance tolerance for nms. Decide whether the junctions are on the line.
      use_heatmap_refinement: Use heatmap refinement method or not.
      heatmap_refine_cfg: The configs for heatmap refinement methods.
      use_junction_refinement: Use junction refinement method or not.
      junction_refine_cfg: The configs for junction refinement methods.
docstr: Local heatmap refinement method.
docstr_tok: ["Local","heatmap","refinement","method","."]
code: def refine_heatmap_local(
      self,
      heatmap: Tensor,
      num_blocks: int = 5,
      overlap_ratio: float = 0.5,
      ratio: float = 0.2,
      valid_thresh: float = 2e-3,
  ) -> Tensor:
      """Local heatmap refinement method."""
      # Get the shape of the heatmap
      H, W = heatmap.shape
      increase_ratio = 1 - overlap_ratio
      h_block = round(H / (1 + (num_blocks - 1) * increase_ratio))
      w_block = round(W / (1 + (num_blocks - 1) * increase_ratio))
  
      # Iterate through each block
      count_map = zeros(
          heatmap.shape, dtype=torch.int, device=heatmap.device
      )
      heatmap_output = zeros(
          heatmap.shape, dtype=torch.float, device=heatmap.device
      )
      for h_idx in range(num_blocks):
          for w_idx in range(num_blocks):
              # Fetch the heatmap
              h_start = round(h_idx * h_block * increase_ratio)
              w_start = round(w_idx * w_block * increase_ratio)
              h_end = h_start + h_block if h_idx < num_blocks - 1 else H
              w_end = w_start + w_block if w_idx < num_blocks - 1 else W
  
              subheatmap = heatmap[h_start:h_end, w_start:w_end]
              if subheatmap.max() > valid_thresh:
                  subheatmap = self.refine_heatmap(
                      subheatmap, ratio, valid_thresh=valid_thresh
                  )
  
              # Aggregate it to the final heatmap
              heatmap_output[h_start:h_end, w_start:w_end] += subheatmap
              count_map[h_start:h_end, w_start:w_end] += 1
      heatmap_output = torch.clamp(
          heatmap_output / count_map, max=1.0, min=0.0
      )
  
      return heatmap_output
  
imports: import math
  from typing import Any, Dict, Optional, Tuple
  import torch
  from kornia.core import Module, Tensor, concatenate, sin, stack, tensor, where, zeros
  from kornia.core.check import KORNIA_CHECK_SHAPE
  from kornia.geometry.bbox import nms
  from kornia.utils import map_location_to_cpu, torch_meshgrid
  from .backbones import SOLD2Net
label_desc: Use image node_id 4 for calling the LineSegmentDetectionModule obj's underlying member method code with example usage: obj.refine_heatmap_local(heatmap, num_blocks, overlap_ratio, ratio, valid_thresh) and returns: heatmap_output