Halcon - Stretch a region - region

How can a region be stretched?
If I have a region, of any shape, and want to stretch it horizontally, but not vertically, how can this be done?

Using the operator zoom_region(Region : RegionZoom : ScaleWidth, ScaleHeight : ).
In your case ScaleHeight=1

Related

Halcon - outer 5 pixels of a image as a region

I have a image with a random shape. What I need to do is to get the outermost 5 pixels of the image as a region. How can this be done in halcon?
what I did so far is this:
threshold (ImageL, FullRegion, 0,255)
erosion_circle(FullRegion, FullRegionErosion,5)
complement(FullRegionErosion, Region2)
intersection(FullRegion, Region2, Border)
It works, but I dont like it.. it seems like a hack to me..
Image domain and get_image_size can be used for a less "hacky" solution:
get_image_size (Image, Width, Height)
get_domain (Image, Domain)
gen_rectangle1 (Rectangle, 5, 5, Height-6, Width-6)
difference (Domain, Rectangle, RegionDifference)

How to scale a barplot in tikz without scaling the text?

I have a barplot in latex in tikz, that I want to scale (reduce width, increase length), but without the text having the same effect.
\begin{figure}
\centering
\resizebox{0.8\textwidth}{1.3\textwidth}{
\begin{tikzpicture}
\pgfplotsset{every tick label/.append style={font=\tiny}}
\begin{axis}[ xmajorgrids=true,
xbar, xmin=0,
xlabel={Gini Coefficient, OECD Countries \%},
symbolic y coords={{Australia},{Austria},{Belgium},{Canada},{Chile},{Costa Rica},{Czech Republic},{Denmark},{Estonia},{Finland},{France},{Germany},{Greece},{Hungary},{Iceland},{Ireland},{Israel},{Italy},{Japan},{Korea},{Latvia},{Lithuania},{Luxembourg},{Mexico},{Netherlands},{New Zealand},{Norway},{Poland},{Portugal},{Slovak Republic},{Slovenia},{South Africa},{Spain},{Sweden},{Switzerland},{Turkey},{United Kingdom},{United States}},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
ytick=data,
]
\addplot[fill=blue!90,draw=black!70,tickwidth = 0pt,bar width=4pt,label style={font=\small}, tick label style={font=\small}] coordinates {(0.33,{Australia}) (0.284,{Austria}) (0.266,{Belgium}) (0.307,{Canada}) (0.454,{Chile}) (0.48,{Costa Rica}) (0.253,{Czech Republic}) (0.263,{Denmark}) (0.314,{Estonia}) (0.266,{Finland}) (0.291,{France}) (0.294,{Germany}) (0.333,{Greece}) (0.288,{Hungary}) (0.255,{Iceland}) (0.297,{Ireland}) (0.344,{Israel}) (0.328,{Italy}) (0.339,{Japan}) (0.355,{Korea}) (0.346,{Latvia}) (0.378,{Lithuania}) (0.304,{Luxembourg}) (0.458,{Mexico}) (0.285,{Netherlands}) (0.349,{New Zealand}) (0.262,{Norway}) (0.284,{Poland}) (0.331,{Portugal}) (0.241,{Slovak Republic}) (0.244,{Slovenia}) (0.62,{South Africa}) (0.341,{Spain}) (0.282,{Sweden}) (0.296,{Switzerland}) (0.404,{Turkey}) (0.351,{United Kingdom}) (0.391,{United States})};
\end{axis}
\end{tikzpicture}
}
\caption{\small{Gini coefficient, OECD countries, 2017 or latest available, source: \url{https://data.oecd.org/inequality/income-inequality.htm}}}
\label{fig:giniOECD}
\end{figure}
I would like the bar charts a bit further apart to each other, the blank areas on top and at the end to be removed, the markers (text within the chart that show the values) to be smaller and all the text to be at normal scale, not skewed like that.
Never ever use \resizebox (or \scalebox) for things that contain text.
to set the height and the width of a pgfplot, the height and width keywords can be used
don't put formatting instructions in arguments of macros like \caption. If you want the caption in another font size, you can adjust it with the help of the caption package
\documentclass{article}
\usepackage{pgfplots}
\usepackage{hyperref}
\usepackage[font=small]{caption}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\pgfplotsset{%
width=.8\textwidth,
height=1.5\textwidth
}
\begin{axis}[
xmajorgrids=true,
xbar,
xmin=0,
xlabel={Gini Coefficient, OECD Countries \%},
symbolic y coords={{Australia}, {Austria}, {Belgium}, {Canada}, {Chile}, {Costa Rica}, {Czech Republic}, {Denmark}, {Estonia}, {Finland}, {France}, {Germany}, {Greece}, {Hungary}, {Iceland}, {Ireland}, {Israel}, {Italy}, {Japan}, {Korea}, {Latvia}, {Lithuania}, {Luxembourg}, {Mexico}, {Netherlands}, {New Zealand}, {Norway}, {Poland}, {Portugal}, {Slovak Republic}, {Slovenia}, {South Africa}, {Spain}, {Sweden}, {Switzerland}, {Turkey}, {United Kingdom}, {United States}},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
enlarge y limits=0.02,
]
\addplot[fill=blue!90,draw=black!70,tickwidth = 0pt,bar width=4pt,label style={font=\small}, tick label style={font=\small}] coordinates {(0.33,{Australia}) (0.284,{Austria}) (0.266,{Belgium}) (0.307,{Canada}) (0.454,{Chile}) (0.48,{Costa Rica}) (0.253,{Czech Republic}) (0.263,{Denmark}) (0.314,{Estonia}) (0.266,{Finland}) (0.291,{France}) (0.294,{Germany}) (0.333,{Greece}) (0.288,{Hungary}) (0.255,{Iceland}) (0.297,{Ireland}) (0.344,{Israel}) (0.328,{Italy}) (0.339,{Japan}) (0.355,{Korea}) (0.346,{Latvia}) (0.378,{Lithuania}) (0.304,{Luxembourg}) (0.458,{Mexico}) (0.285,{Netherlands}) (0.349,{New Zealand}) (0.262,{Norway}) (0.284,{Poland}) (0.331,{Portugal}) (0.241,{Slovak Republic}) (0.244,{Slovenia}) (0.62,{South Africa}) (0.341,{Spain}) (0.282,{Sweden}) (0.296,{Switzerland}) (0.404,{Turkey}) (0.351,{United Kingdom}) (0.391,{United States})};
\end{axis}
\end{tikzpicture}
\caption{Gini coefficient, OECD countries, 2017 or latest available, source: \url{https://data.oecd.org/inequality/income-inequality.htm}}
\label{fig:giniOECD}
\end{figure}
\end{document}

OpenCV Seamless Cloning shift position after finish the process

I am trying to used the seamsless cloning to blend to image together.
but I notice that after using the seamsless clone function the area in the
mask that I want to transfer is shift upward. So I have a question that
is this a normal behaviour of the seamsless clone function or it is a bug
on my implementation.
Here are the Source photo
Here are the destination photo
Here are the result photo
I encountered similar situation. Moreover, like #JoshuaCWebDeveloper noted, this shift disappeared when all one mask is used. Nevertheless, I got a fix for this. What I did is this. I cropped valid mask (non-zero sub-section) out using cv2.boundingRect. So my source image and mask image are reduced to a smaller size, while center is now calculated from boundingRect outputs (Since reference point is marked on destination image). This way, error got solved/shift got ridden.
(Based on the answer posted by Fractalic Forieu) You can achieve the same result without reducing the image size.
Instead of using the image center:
center = (width // 2, height // 2)
poissonImage = cv2.seamlessClone(srcImage, dstImage, maskImage, center)
use the center of the bounding rect:
monoMaskImage = cv2.split(maskImage)[0] # reducing the mask to a monochrome
br = cv2.boundingRect(monoMaskImage) # bounding rect (x,y,width,height)
centerOfBR = (br[0] + br[2] // 2, br[1] + br[3] // 2)
poissonImage = cv2.seamlessClone(srcImage, dstImage, maskImage, centerOfBR )

How to set a title for a Border with LWUIT 1.4 ? How to coloriate odd and pair Table rows?

I use LWUIT 1.4
1) In my Form there is a Container based on a BoxLayout ( Y axis ) , there are two Label's added to this container , and I want to create a titled Border to be placed into the container so it surrounds the two labels. I know to create a Border , but I do not know how to set a title to the Border with LWUIT 1.4 ! So how to set a title to a Border with LWUIT 1.4 ?
2) In my Form there is a Table based on the DefaultTableModel class whose getValueAt method is implemented with an enumeration of a recordstore , and I want that the rows of the Table are colored according to the index of the row : for example when the row index is odd then its background color should be white , and if the row index is pair then its background color should be gray. How to achieve that ?
3) Why do not the TableLayout.Constraint methods work ? I want to make two columns of a Table to have equal size , that is 50% of the Table total width for each column , but when I run the application then the first column is not equally sized with the second column when its data are not long enough ! So how to make the columns equally sized ?
Thank you very much indeed
1) There is a titled border in the trunk but I think it was added in 1.4.
You can draw something like this by overriding the Container paintBorder method (notice you will need sufficient component padding for the border to appear properly. This is the code from the SVN version, should work with very little changes (just change c to this):
Font f=c.getStyle().getFont();
int titleW=f.stringWidth(borderTitle);
int topPad=c.getStyle().getPadding(Component.TOP);
int topY=y+(topPad-thickness)/2;
if (c.isRTL()) {
g.fillRect(x+width-TITLE_MARGIN, topY, TITLE_MARGIN , thickness); //top (segment before the title)
g.fillRect(x, topY, width-(TITLE_MARGIN +titleW+TITLE_SPACE*2), thickness); //top (segment after the title)
g.drawString(borderTitle, x+width-(TITLE_MARGIN +titleW+TITLE_SPACE), y+(topPad-f.getHeight())/2);
} else {
g.fillRect(x, topY, TITLE_MARGIN , thickness); //top (segment before the title)
g.fillRect(x+TITLE_MARGIN +titleW+TITLE_SPACE*2, topY, width-(TITLE_MARGIN +titleW+TITLE_SPACE*2), thickness); //top (segment after the title)
g.drawString(borderTitle, x+TITLE_MARGIN+TITLE_SPACE, y+(topPad-f.getHeight())/2);
}
g.fillRect(x, y+height-thickness, width, thickness); //bottom
g.fillRect(x, topY, thickness, height); //left
g.fillRect(x+width-thickness, topY, thickness, height); //right
2) Derive table and override the method:
protected Component createCell(Object value, int row, int column, boolean editable)
call super.createCell() and set the UIID of the returned value to "OddRow","EvenRow" appropriately. Style in the resource editor or theme to anything you like.
3) I'm not aware of such an issue. If this happens on the current SVN you should file an issue in the projects issue tracker.
I downloaded the latest Resource Editor from your blog site , and I defined the background and border "selected" versions of the component TableCell , but the extra-rectangle is always shown in runtime when I click on a last column table cell ! I tried to call tableName.repaint() in the component focusGained() implemented method , because I registered it to a focuslistener , but the rectangle does not disappear.
I created a Dialog to show the selected row number and when the Dialog is shown when I click the third softbutton then the rectangle disappeared !!! Perhaps the focus is lost from the table cell !! And whenever I fire then I got the same row number as before ; so there is no row number error. So what code should I write , or what property should I edit in the Editor to get the same effect as of displaying the Dialog to make the rectangle disappear ?

How can I "best fit" an arbitrary cairo (pycairo) path?

It seems like given the information in stroke_extents() and the translate(x, y) and scale(x, y) functions, I should be able to take any arbitrary cairo (I'm using pycairo) path and "best fit" it. In other words, center it and expand it to fill the available space.
Before drawing the path, I have scaled the canvas such that the origin is the lower left corner, up is y+, right is x+, and the height and width are both 1. Given these conditions, this code seems to correctly scale the path:
# cr is the canvas
extents = cr.stroke_extents()
x_size = abs(extents[0]) + abs(extents[2])
y_size = abs(extents[1]) + abs(extents[3])
cr.scale(1.0 / x_size, 1.0 / y_size)
I cannot for the life of me figure out the translating though. Is there a simpler approach? How can I "best fit" a cairo path on its canvas?
Please ask for clarification if anything is unclear in this question.
I have found a solution that I like (at least for my purposes). Just create a new surface and paint the old surface on to the new one.
As for the scale only, I have done a similar thing to adjust an image inside a box with a "best-fit" approach. As about scale, here is the code:
available_width = 800
available_height = 600
path_width = 500
figure_height = 700
# formulas
width_ratio = float(available_width)/path_width
height_ratio = float(available_height)/figure_height
scale = min(height_ratio, width_ratio)
# result
new_path_width = path_width*scale
new_figure_height = figure_height*scale
print new_path_width, new_figure_height
The image gets drawn aligned to the origin (top left in my case), so perhaps a similar thing should be done to translate the path.
Also, this best fit is intended to preserve aspect ratio. If you want to stretch the figure, use each of the ratios instead of the 'scale' variable.
Hope I have helped

Resources