MATLAB: How to control the thickness and line style of the bounding box in the IMPOLY function in Image Processing Toolbox 6.3 (R2009a)

Image Processing Toolbox

I would like to control propertied like the thickness and linestyle of the polygon created with the IMPOLY function in Image Processing Toolbox 6.3 (R2009a):
figure, imshow('gantrycrane.png');
h = impoly(gca, [188,30; 189,142; 93,141; 13,41; 14,29]);

Best Answer

The ability to control the thickness of the line in the polygon created with the IMPOLY function is not available in Image Processing Toolbox 6.3 (R2009a).
As a workaround, you can use the following undocumented steps to change the thickness of the polygon line. Note that although these steps should be effective for the Image Processing Toolbox 6.3 (R2009a), there is no guarantee that they will be effective in other versions of the Image Processing Toolbox. The suggested workaround also might cause unexpected behavior elsewhere in your code.
To change the thickness of the bounding box of the IMPOLY follow the steps outlined below:
1. Locate and open for editing polygonSymbol function by executing the following:
A=which('-all','polygonSymbol');
edit(A{:})
2. In definition of h_close_line_bottom in line 49, replace the following line :
'LineWidth', 3*line_width, ...
with
'LineWidth', 1*line_width, ...
3. In function makeBottomLine, in line 182, replace the following line:
'LineWidth', 3*line_width, ...
with
'LineWidth', 1*line_width, ...
4. Save the file by clicking on the "disk" icon in the MATLAB editor, and close the editor.
5. Use IMPOLY as usual. The bounding box should now be 1 pixel thick.
 
Another workaround is to get the handle to the IMPOLY object and then find the line objects. Once you have this you can change the line width using SET as shown below. To change other properties, replace the property name as appropriate. For example, to change the line style you can set the property 'linestyle' to the required value.
 
figure
imshow('gantrycrane.png');
h = impoly(gca, [188,30; 189,142; 93,141; 13,41; 14,29]);
%find line objects
lines = findall(h,'type','line');
set(lines,'linewidth','--')