how to make a black box on the image without edit the image

9 次查看(过去 30 天)
I have done the code to make a box which is first, I find 4 different point and make a connection between those point. Next, I have to turn all the values in the box into 0 which is the value for black color. Then i got a black box. My problem is how do i want to put the black box on the image?

回答(2 个)

Saneem Ahmed
Saneem Ahmed 2011-3-31
i am not able to understand your problem fully.Assuming that you want to make a box region in an image black in color: that will be pretty easy.let 'im' be image, and let (x1,y1) be co-ordinates of left top point and (x2,y2) be bottom right point of the box.
imx=im;
imx(x1:x2,y1:y2,:)=0; %this is for color image.
imx(x1:x2,y1:y2)=0; %for gray image.

Walter Roberson
Walter Roberson 2011-3-31
If you want to visually overlay the black box on to the existing image, then you can image() the black box in to the same axes as the original image, and set the AlphaData properties of the new image so that it is transparent (Alpha 0) outside the black box and opaque (Alpha 1) inside the black box.
In some cases you might prefer to instead create a black rectangle under the existing (original) image, and set the AlphaData properties of the existing (original) image to be transparent (Alpha 0) inside where you want the black box to be, so that the black underlay shows through.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by