Choose Interpolation for Images and Masks
A resize makes a segmentation mask acquire new class values.
Read the full lesson and open its transcript below. A narrated video will be added after production.
What you will learn
A resize makes a segmentation mask acquire new class values.
A practical question
After resizing the conveyor image, its segmentation mask contains values that were never class labels. How did that happen? The same smooth interpolation that looks fine on a photograph was applied to a categorical mask.
The useful idea
For photo intensities, estimating a value between sampled pixels may give a smoother display. For a mask, the numbers name classes. Halfway between class one and class two is not a meaningful new category. Nearest-neighbor interpolation chooses one existing label at each output location, keeping the mask's values valid. The image and mask still use the same geometry even though their value interpolation differs.
Work through the example
Make a tiny mask with two known class IDs, resize it, and list the unique output values. If an unexpected number appears, the interpolation choice is wrong for that mask. Then overlay it on the resized photo. Valid label numbers are only one check; the object outlines also need to stay aligned. A photograph and a category mask need different interpolation. Smooth interpolation can be helpful for intensity values when an image is resized. In a two-class mask, averaging neighboring labels can create numbers that are not valid classes at all. Resize the photograph with the chosen image method, but use a label-preserving method for the mask. Inspect the boundary afterward, because preserving label IDs does not guarantee that the resized outline still matches the object perfectly. Now check the idea on a concrete example: Resize a two-class mask and check that every output pixel remains one of the original class IDs. A possible trap is worth naming: Treating labels as continuous intensities can invent invalid categories. The answer follows from that evidence: Images may use smooth interpolation; categorical masks normally use nearest-neighbor interpolation.
Limits and next step
Keep the original pair and the warp settings. Next, we'll compare two complete views and measure how well their matching points line up.
Worked example
Resize a two-class mask and check that every output pixel remains one of the original class IDs.
Quick check: test your understanding
Try it yourself: Consider this case: Resize a two-class mask and check that every output pixel remains one of the original class IDs. Explain how you would check the result. In your answer, address this limitation: Treating labels as continuous intensities can invent invalid categories.
Check the reasoning
Images may use smooth interpolation; categorical masks normally use nearest-neighbor interpolation. Treating labels as continuous intensities can invent invalid categories.
What is the main idea behind choose interpolation for images and masks?
Images may use smooth interpolation; categorical masks normally use nearest-neighbor interpolation.
How is it used in the example?
Resize a two-class mask and check that every output pixel remains one of the original class IDs.
What limitation should be checked?
Treating labels as continuous intensities can invent invalid categories.
Further reading
Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.
Original ToolsInVision teaching examples. Editorial approach · Suggest a correction
Accessible referenceLesson 51 transcript306 words · Narration ready for the upcoming videoOpen transcript
After resizing the conveyor image, its segmentation mask contains values that were never class labels. How did that happen? The same smooth interpolation that looks fine on a photograph was applied to a categorical mask.
For photo intensities, estimating a value between sampled pixels may give a smoother display. For a mask, the numbers name classes. Halfway between class one and class two is not a meaningful new category. Nearest-neighbor interpolation chooses one existing label at each output location, keeping the mask's values valid. The image and mask still use the same geometry even though their value interpolation differs.
Make a tiny mask with two known class IDs, resize it, and list the unique output values. If an unexpected number appears, the interpolation choice is wrong for that mask. Then overlay it on the resized photo. Valid label numbers are only one check; the object outlines also need to stay aligned. A photograph and a category mask need different interpolation. Smooth interpolation can be helpful for intensity values when an image is resized. In a two-class mask, averaging neighboring labels can create numbers that are not valid classes at all. Resize the photograph with the chosen image method, but use a label-preserving method for the mask. Inspect the boundary afterward, because preserving label IDs does not guarantee that the resized outline still matches the object perfectly. Now check the idea on a concrete example: Resize a two-class mask and check that every output pixel remains one of the original class IDs. A possible trap is worth naming: Treating labels as continuous intensities can invent invalid categories. The answer follows from that evidence: Images may use smooth interpolation; categorical masks normally use nearest-neighbor interpolation.
Keep the original pair and the warp settings. Next, we'll compare two complete views and measure how well their matching points line up.