creating function that input a colored image

조회 수: 1 (최근 30일)
idan
idan 2022년 7월 25일
답변: Vidip Jain 2023년 9월 6일
hello,
I would like to know how to creating a function whose input is a colored image (a 3-dimensional tensor of type uint8) and a positive integer value representing the thickness of the line (in pixels) that you want to draw on the image.
Thanks.

답변 (1개)

Vidip Jain
Vidip Jain 2023년 9월 6일
I understand that you want to know how to create a function whose input is a coloured image (a 3-dimensional tensor of type uint8) and a positive integer value representing the thickness of the line (in pixels) that you want to draw on the image.
To create such a function, you start by defining it with two input parameters: the coloured image and the line thickness, both of which are passed to the function. Next, you need to make a copy of the input image to avoid modifying the original. This is essential to preserve the integrity of the original data.
Determine the starting and ending points for the line on the image. To actually draw the line, you'll create a binary mask of the same size as the image. You can use MATLAB's image drawing functions (e.g., insertShape) to draw the line on this mask.
With the binary mask representing the line, you apply it to the image. Iterate through each colour channel of the image (typically Red, Green, and Blue) and multiply each channel by the binary mask. This operation effectively draws the line on each channel of the image.
Finally, you return the modified image as the output of your function. The result will be the input image with the line drawn on it, based on your specified thickness, colour, and position. This function can be called with different images and thickness values to draw lines on them as needed.
Refer to this documentation for more information: https://www.mathworks.com/help/vision/ref/insertshape.html

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by