代码拉取完成,页面将自动刷新
同步操作将从 小墨/力扣题库(完整版) 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> grid <code>image</code> which represents a grayscale image, where <code>image[i][j]</code> represents a pixel with intensity in the range<code>[0..255]</code>. You are also given a <strong>non-negative</strong> integer <code>threshold</code>.</p>
<p>Two pixels <code>image[a][b]</code> and <code>image[c][d]</code> are said to be <strong>adjacent</strong> if <code>|a - c| + |b - d| == 1</code>.</p>
<p>A <strong>region</strong> is a <code>3 x 3</code> subgrid where the <strong>absolute difference</strong> in intensity between any two <strong>adjacent</strong> pixels is <strong>less than or equal to</strong> <code>threshold</code>.</p>
<p>All pixels in a <strong>region</strong> belong to that region, note that a pixel <strong>can</strong> belong to <strong>multiple</strong> regions.</p>
<p>You need to calculate a <strong>0-indexed</strong> <code>m x n</code> grid <code>result</code>, where <code>result[i][j]</code> is the <strong>average</strong> intensity of the region to which <code>image[i][j]</code> belongs, <strong>rounded down</strong> to the nearest integer. If <code>image[i][j]</code> belongs to multiple regions, <code>result[i][j]</code> is the <strong>average </strong>of the<strong> rounded down average </strong>intensities of these regions, <strong>rounded down</strong> to the nearest integer. If <code>image[i][j]</code> does<strong> not</strong> belong to any region, <code>result[i][j]</code> is <strong>equal to</strong> <code>image[i][j]</code>.</p>
<p>Return <em>the grid</em> <code>result</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/example0corrected.png" style="width: 832px; height: 275px;" />
<pre>
<strong>Input:</strong> image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3
<strong>Output:</strong> [[9,9,9,9],[9,9,9,9],[9,9,9,9]]
<strong>Explanation:</strong> There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9.
Please note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.
</pre>
<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/example1corrected.png" style="width: 805px; height: 377px;" />
<pre>
<strong>Input:</strong> image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12
<strong>Output:</strong> [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]
<strong>Explanation:</strong> There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27. All the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1
<strong>Output:</strong> [[5,6,7],[8,9,10],[11,12,13]]
<strong>Explanation:</strong> There does not exist any region in image, hence result[i][j] == image[i][j] for all the pixels.
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= n, m <= 500</code></li>
<li><code>0 <= image[i][j] <= 255</code></li>
<li><code>0 <= threshold <= 255</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。