Halcon - Affine transformation for NCC model matching with scale down image using image pyramid - halcon

Hi i have an issue with affine transformation of a NCC model matching (NumLevel 4, because i have a large image).
I have created a NCC model in scale down image pyramid (GenGaussPyramid)
Then find NCC model in the scale down image.
Anyone know how to affine transfer the found model region back to original image (NumLevel 1)?

I did you a small demo.
The core is where it's written reverse affine transformation.
Here the code
* test image with the pattern (circle)
gen_image_const (EmptyImage, 'byte', 640, 480)
OriginalRow :=240
OriginalColumn := 400
OriginalRadius := 8
gen_circle (Circle, OriginalRow ,OriginalColumn, OriginalRadius)
gen_circle_contour_xld (CircleXLD, OriginalRow, OriginalColumn, OriginalRadius, 0, 6.28318, 'positive', 0.1)
paint_xld (CircleXLD, EmptyImage, OriginalTestImage, 255)
dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
stop()
* creation of pyramid image
Scale := 0.5
gen_gauss_pyramid (OriginalTestImage, ImagePyramid, 'weighted', Scale)
LevelIndex := 4
select_obj (ImagePyramid, Level, LevelIndex )
* ideal found circle
LevelScale := pow(Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, OriginalRow*LevelScale -OriginalRow, OriginalColumn*LevelScale - OriginalColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, LevelScale, LevelScale, OriginalRow*LevelScale+0.5, OriginalColumn*LevelScale+0.5, HomMat2DScale)
affine_trans_contour_xld (CircleXLD, IdealFoundCircleXLD, HomMat2DScale)
* simulation of searching in the 4th level
threshold_sub_pix (Level, Border, 128)
area_center_xld (Border, Area, FoundRow, FoundColumn, _)
FoundRadius:= sqrt(Area/3.14)
gen_circle_contour_xld (FoundCircleXLD, FoundRow, FoundColumn, FoundRadius, 0, 6.28318, 'positive', 0.1)
dev_display (Level)
dev_set_draw ('margin')
dev_set_color ('green')
dev_display (IdealFoundCircleXLD)
dev_set_color ('red')
dev_display (FoundCircleXLD)
stop()
* reverse affine transformation
ReverseLevelScale := pow(1/Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, FoundRow*ReverseLevelScale -FoundRow, FoundColumn*ReverseLevelScale - FoundColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, ReverseLevelScale, ReverseLevelScale, FoundRow*ReverseLevelScale+0.5, FoundColumn*ReverseLevelScale+0.5, HomMat2DScale)
affine_trans_contour_xld (IdealFoundCircleXLD, ReverseIdealFoundCircleXLD, HomMat2DScale)
affine_trans_contour_xld (FoundCircleXLD, ReverseFoundCircleXLD, HomMat2DScale)
dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
dev_set_color ('green')
dev_display (ReverseIdealFoundCircleXLD)
dev_set_color ('red')
dev_display (ReverseFoundCircleXLD)
stop()

Related

Halcon - get lowest pixel of a region along a line

I have a random region, and would need the coordinates in the world plane of the intersection between the region and the center of the image, with the highest y coordinate.
this is what I have so far:
fill_up(SelectedRegions, RegionFillUp)
get_image_size(Image, w,h)
gen_region_line(RegionLine,0,w/2,h,w/2)
disp_line (3600, 0, w/2, h, w/2)
intersection (RegionFillUp, RegionLine, RegionIntersection)
*EDIT
I've made some progress and have now all the intersections. But cannot figure out how to get the last entry of the array if the array is bigger than one...
gen_contour_region_xld (RegionFillUp, Contours, 'border')
get_image_size(Image, w,h)
gen_contour_polygon_xld (Line1,[0,h],[w/2,w/2])
intersection_line_contour_xld(Contours,0,w/2,h,w/2,rowcoords, columncoords, isOverlapping)
Solved it this way:
fill_up(SelectedRegions, RegionFillUp)
gen_contour_region_xld (RegionFillUp, Contours, 'border')
get_image_size(Image, w,h)
intersection_line_contour_xld(Contours,0,w/2,h,w/2,rowcoords, columncoords, isOverlapping)
disp_cross (3600, rowcoords, columncoords, 6, 0)
tuple_length (rowcoords,Length)
Position := 0
if (Length > 0)
Position := rowcoords[Length-1]
endif
image_points_to_world_plane (CamParam, Pose, Position, w/2, 1, X1, Y1)

Place two tikzpictures next to eachother LaTeX

I have two tikzpitctures in LaTeX that I was hoping to place side-by-side. Does anybody know a solid way of accomplishing this? If not, is there another approach to creating side-by-side Venn Diagrams?
Code:
% %%%%%%%%%%%%%%%%%%%
\section*{Question 1}
% %%%%%%%%%%%%%%%%%%%
{\bfseries Determine the relationship between $P = (A-B)-C$ and $Q = (A-C)-(B-C)$}
{\bfseries Answer: $P = Q$}
% %%%%%%%%%%%%%%%%%%%
\subsection*{Justification 1: Venn Diagram}
% %%%%%%%%%%%%%%%%%%%
\def\firstcircle{ (0.0, 0.0) circle (1.5)}
\def\secondcircle{(2.0, 0.0) circle (1.5)}
\def\thirdcircle{ (1.0,-1.5) circle (1.5)}
\def\rectangle{ (-1.5,-3.0) rectangle (3.5,1.0) }
\colorlet{circle edge}{black}
\colorlet{circle area}{blue!30}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\begin{tikzpicture}
\begin{scope}
\fill[filled] \firstcircle;
\fill[white] \secondcircle;
\fill[white] \thirdcircle;
\end{scope}
\draw[outline] \firstcircle node[left] {$A$};
\draw[outline] \secondcircle node[right] {$B$};
\draw[outline] \thirdcircle node[below] {$C$};
\node[anchor=south] at (current bounding box.north)
{$P = (A - B) - C$};
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}
\fill[filled] \firstcircle;
\fill[white] \secondcircle;
\fill[white] \thirdcircle;
\end{scope}
\draw[outline] \firstcircle node[left] {$A$};
\draw[outline] \secondcircle node[right] {$B$};
\draw[outline] \thirdcircle node[below] {$C$};
\node[anchor=south] at (current bounding box.north)
{$Q = (A - C) - (B - C)$};
\end{tikzpicture}
\pagebreak
Result:
You force the two images to be in separate lines by leaving an empty line between the two pictures. For latex an empty line marks the start of a new paragraph.
\documentclass{article}
\usepackage{tikz}
\begin{document}
% %%%%%%%%%%%%%%%%%%%
\section*{Question 1}
% %%%%%%%%%%%%%%%%%%%
{\bfseries Determine the relationship between $P = (A-B)-C$ and $Q = (A-C)-(B-C)$}
{\bfseries Answer: $P = Q$}
% %%%%%%%%%%%%%%%%%%%
\subsection*{Justification 1: Venn Diagram}
% %%%%%%%%%%%%%%%%%%%
\def\firstcircle{ (0.0, 0.0) circle (1.5)}
\def\secondcircle{(2.0, 0.0) circle (1.5)}
\def\thirdcircle{ (1.0,-1.5) circle (1.5)}
\def\rectangle{ (-1.5,-3.0) rectangle (3.5,1.0) }
\colorlet{circle edge}{black}
\colorlet{circle area}{blue!30}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\begin{tikzpicture}
\begin{scope}
\fill[filled] \firstcircle;
\fill[white] \secondcircle;
\fill[white] \thirdcircle;
\end{scope}
\draw[outline] \firstcircle node[left] {$A$};
\draw[outline] \secondcircle node[right] {$B$};
\draw[outline] \thirdcircle node[below] {$C$};
\node[anchor=south] at (current bounding box.north)
{$P = (A - B) - C$};
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{scope}
\fill[filled] \firstcircle;
\fill[white] \secondcircle;
\fill[white] \thirdcircle;
\end{scope}
\draw[outline] \firstcircle node[left] {$A$};
\draw[outline] \secondcircle node[right] {$B$};
\draw[outline] \thirdcircle node[below] {$C$};
\node[anchor=south] at (current bounding box.north)
{$Q = (A - C) - (B - C)$};
\end{tikzpicture}
\pagebreak
\end{document}
You can always draw a huge
Grid, I have this exact problem... and I draw a grid,
Especially if your scheme is a progression where most things stay the same..but a few things change for each new image... like a cartoon... you will just have the alter the coordinates when you copy the new picture..
It’s very easy to space everything and tailor it to your aesthetic...
You can even use different step sizes on the grid.
Once you’ve drawn the total scheme, change the grid lines to white and it doesn’t show in the rendered pdf..
Hope that helps

Cut out a custom shape from an image in P5.js

I am trying to create jigsaw puzzle shapes using P5.js. After creating puzzle shapes, I want to cut areas from main image into pieces. For that I have options of using GET() or COPY():
But both of them take fix height and width as parameter. How can I copy a custom area like given in following shapes:
https://editor.p5js.org/techty/sketches/h7qwatZRb
let cutout = createGraphics(w, h);
cutout.background(255, 255);
cutout.blendMode(REMOVE);
//draw shape on cutout
let newshapeimagegraphic = createGraphics(w, h);
newshapeimagegraphic.image(myImg, 0, 0);
newshapeimagegraphic.blendMode(REMOVE);
newshapeimagegraphic.image(cutout, 0, 0);
image(newshapeimagegraphic, 0, 0);

With several ROIs in an image, how can I send the ROI to the back

When I have several ROIs in an image, they can overlap and sometimes the smaller one gets lost behind the bigger one. However, one of the is on "top" and the other is "below." I have the ID of the ROI, but I am missing the command ROI_ID.ROISendToBack() or similar.
Any trick available?
Thanks!
The order of ROIs on a display can not be the property of an individual ROI, but it is a property of the thing 'containing' the ROIs. That's why you search for the command at the wrong place. It is not a command of the ROI object, but of the ImageDisplay object.
Each ImageDisplay contains a "list" of its ROIs and you want to change the order in that list.
The commands for specifying the "order" of ROIs on an ImageDisplay are
There is no command to "move" a ROI, but you can simple remove and re-add it.
image img := RealImage( "Dummy",4, 350, 350)
img = iradius
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
ROI roi1 = NewROI()
roi1.ROISetRectangle( 100, 100, 200, 200 )
roi1.ROISetVolatile(0)
roi1.ROISetColor(1,0,0)
roi1.ROISetDrawFilled(1)
roi1.ROISetFillProperties(0.2,0.1,0,0)
ROI roi2 = NewROI()
roi2.ROISetRectangle( 125, 125, 225, 225 )
roi2.ROISetVolatile(0)
roi2.ROISetColor(0,1,0)
roi2.ROISetDrawFilled(1)
roi2.ROISetFillProperties(0.2,0,0.1,0)
ROI roi3 = NewROI()
roi3.ROISetRectangle( 150, 150, 250, 250 )
roi3.ROISetVolatile(0)
roi3.ROISetColor(0,0,1)
roi3.ROISetDrawFilled(1)
roi3.ROISetFillProperties(0.2,0,0,0.1)
disp.ImageDisplayAddROI( roi1 )
disp.ImageDisplayAddROI( roi2 )
disp.ImageDisplayAddROI( roi3 )
OKDialog( "Now send blue to the bottom" )
disp.ImageDisplayDeleteROI( roi3 )
disp.ImageDisplayAddROIAtBeginning( roi3 )
OKDialog( "Now send red to front" )
disp.ImageDisplayDeleteROI( roi1 )
disp.ImageDisplayAddROIAtEnd( roi1 )

UIView transformation to SVG matrix

I am currently embedding an image into an exported SVG document and am running into an issue with the transformation matrix on a UIView that I am scaling and moving.
My output currently pushes the matrix into the attribute transform
transform="matrix(view.transform.a, view.transform.b, view.transform.c, view.transform.d, view.transform.tx, view.transform.ty)"
This all works perfectly fine with the exception of the tx and ty values of the transformation. For some reason when I scale the view these values start getting weird , and I'm not sure what is going on. Obviously core graphics is handeling the matrix a little different than svg is, but does anyone know what the difference is?
It looks like CoreGraphics sets up the transform so that the vector is in the center of the view while in SVG the vector would be at top left of the image.
Multiplying the transform solved this for me:
// create an offset matrix<br />
CGAffineTransform offset1 = CGAffineTransformMake(1, 0, 0, 1, -originalViewWidth/2, -originalViewHeight/2);
CGAffineTransform offset2 = CGAffineTransformMake(1, 0, 0, 1, originalViewWidth/2, originalViewHeight/2);
CGAffineTransform matrix = CGAffineTransformConcat(offset1, view.transform);
matrix = CGAffineTransformConcat(matrix, offset2);