Matlab to draw a rectangle in the image (box)

Source: Internet
Author: User

function [state,result]=Draw_rect (Data,pointall,windsize,showornot)% function call: [state,result]=Draw_rect (Data,pointall,windsize,showornot)%function function: Draw a rectangular frame in the image%function Input: Data is the original large image, which can be used as a grayscale image, and can be a color graph%The coordinates of the upper- left corner of the Pointall box in the larger view (each row represents a coordinate),%Note: The coordinate system in the diagram is the first column y, and the second column is X (very strange)% windsize Box size windsize=[ the, the] Indicate the length and width respectively%Showornot whether to display, default to show% function Output: state--represents the program result status% Result-result image Data% function History: V0.0@ -- on- -created by AbornifNargin <4Showornot=1; Endrgb= [255 255 0]; %Border Color Linesize=3; % border size, take 1,2,3Windsize (1,1) =windsize (1,1); Windsize (1,2) = Windsize (1,2);ifWindsize (1,1) > Size (data,1) ||... windsize (1,2) > Size (data,2) State= -1; %The Description window is too large, the image is too small, no need to get disp ('The window size is larger then image ...'); return; Endresult=data;ifSize (data,3) ==3     fork=1:3         forI=1: Size (Pointall,1)   %The Draw Border order is: upper right bottom left principle result (Pointall (i,1), Pointall (I,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1) +windsize (I,2), Pointall (I,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2), k) = RGB (1, K); ifLinesize = =2|| Linesize = =3result (Pointall (i,1)+1, Pointall (i,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2) +windsize (I,1)-1, k) = RGB (1, K); Result (Pointall (i,1) +windsize (I,2)-1, Pointall (i,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2)-1, k) = RGB (1, K); ifLinesize = =3result (Pointall (i,1)-1, Pointall (i,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2) +windsize (I,1)+1, k) = RGB (1, K); Result (Pointall (i,1) +windsize (I,2)+1, Pointall (i,2):p Ointall (i,2) +windsize (I,1), k) = RGB (1, K); Result (Pointall (i,1):p Ointall (i,1) +windsize (I,2), Pointall (I,2)+1, k) = RGB (1, K); End End End Endendstate=1;ifShowornot = =1Figure ; Imshow (result); end

The following is called in the main function:

%= imread ('man_1.jpg'= [5]= [100 ,+]; [State,results] =Draw_rect (data,pointall,windsize); return;

The original image is:

The resulting image is:

Special note: The coordinate system shown in the image is not the same as what we usually use!!!

from:http://blog.csdn.net/loveaborn/article/details/8545809

Matlab to draw a rectangle in the image (box)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.