Is the point on the inner border? - pascal

There is an algorithm, it subtracts a point into a circle, an outer / inner boundary, or a figure inside the circle. But I encountered such a problem, it does not correctly display the information about the hit on the inner border of the figure that is inside the circle. For example, if you specify a coordinate (-14; 0), it will output a "point on the internal border" and if for example to specify a coordinate (0; 3), which also falls on the border, it will simply output the "point enters the region". I can not understand where I made a mistake, please tell me how to fix it?
if (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]>=0) or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=-14)or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]<=round(-b/2)) or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]>=round(b/2))
then t:=t+1;
if (x[i]*x[i]+y[i]*y[i]>r*r) then begin
TextOut(65, f, ' - point outside the region');
f:=f+16;
end
else if (x[i]*x[i]+y[i]*y[i]=r*r) then begin
TextOut(65, f, ' - point on the outer boundary');
f:=f+16;
end
else if (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]>=0) or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<-14) or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]<round(-b/2)) or
(x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]>round(b/2))
then begin
TextOut(65, f, '- the point is the area');
f:=f+16;
end
else if ((x[i]=0) and (y[i]<15) and (y[i]=15)) or
((x[i]=-14) and (y[i]<15) and (y[i]>-15)) or
((y[i]=15) and (x[i]<0) and (x[i]>-14)) or
((y[i]=-15) and (x[i]<0) and (x[i]>-14))
then begin
TextOut(65, f, ' - internal point');
f:=f+16;
end
else begin
TextOut(65, f, ' - dot in the inner figure');
f:=f+16;
end
end;

You did not show the code that draws the rectangle but I guess you use normal GDI functions. According to MS Rectangle function a rectangle does not include its right and bottom sides.
For example Rect(-14, 15, 0, -15) does not include the X=0 pixels, nor the y=-15 pixels.
See Why are RECTs endpoint-exclusive? by Raymond Chen about reasons and consequences.

I believe this section is attempting to identify points on the border of the rectangle:
else if ((x[i]=0) and (y[i]<15) and (y[i]=15)) or
((x[i]=-14) and (y[i]<15) and (y[i]>-15)) or
((y[i]=15) and (x[i]<0) and (x[i]>-14)) or
((y[i]=-15) and (x[i]<0) and (x[i]>-14))
I believe the first y[i]=15 should be an inequality, and that the inequalities should include equality as an option, in order to detect points on the corners of the rectangle.
else if ((x[i]=0) and (y[i]<=15) and (y[i]>=-15)) or
((x[i]=-14) and (y[i]<=15) and (y[i]>=-15)) or
((y[i]=15) and (x[i]<=0) and (x[i]>=-14)) or
((y[i]=-15) and (x[i]<=0) and (x[i]>=-14))

Related

Usage of pascal variant record

I need help from those who know the pascal very well.
I need (teachers requirement) to use a variant record. Those variant record are defined like this:
Temperature = record
case scale : TemperatureScale of
celsius : (celsius_value : ScaleCelsius);
kelvin : (kelvin_value : ScaleKelvin);
end;
According to primary sources I found during my research about this topic, I could not find how to use variant record, only how to declare it.
My primary sources: google search(found nothing), Case-Freepascal and Record-Freepascal
Edit for those who wonder what i must use in implementation it is exacly this:
type
UkPolozka = ^Polozka;
UkHodnota = ^Hodnota;
TypUdaj=(typretez, typcele, typrealne, typlogik, typpole, typobjekt);
VarZaznam = record
case Udaj: TypUdaj of
typretez: (retez: string);
typcele: (cele: word);
typrealne: (realne: single);
typlogik: (logik: boolean);
typpole: (pole: UkHodnota);
typobjekt: (objekt: UkPolozka);
end;
Polozka = record
Nazev: string;
Hodn: VarZaznam;
Dalsi: UkPolozka
end;
Hodnota = record
Hodn: VarZaznam;
Dalsi: UkHodnota
end;
Consider example record from Delphi Help. I modified it with tag.
Tag usage is optional and usually is not used and doesn't provide useful information.
Note that the first line outputs radius with the same value as height - they share the same memory.
Then I explicitly set tag (but fields stay the same)
Also note size difference for no-tag record and tagged one.
Note again - in most cases programmers don't define or use tag value. It might be unsafe to rely on tag (until you follow strict rules in assigning tags). I did not set rectangle tag, but program consider zero tag as the first variant.
Just assign needed field by name. Just read needed field by name. For your example varVarZaznam.retez:= 'test';
type
TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
TFigure = record
case shape: TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
TFigureNoTag = record
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
var
Fig: TFigure;
begin
Fig.Height := 5;
Fig.Width := 3;
//default tag is zero = Rectangle
if Fig.shape = Rectangle then
Writeln('Rect ', Fig.Height:3:0, Fig.Width:3:0, Fig.Radius:3:0)
else
Writeln('not Rect');
Fig.shape := Circle;
if Fig.shape <> Rectangle then
Writeln('not Rect');
Writeln('Fig size ', SizeOf(TFigure), ' noTag size ', SizeOf(TFigureNoTag));
Readln;
output in Delphi:
Rect 5 3 5
not Rect
Fig size 32 noTag size 24

find fingertips and valley point of hand in MATLAB

I am working on palm print identification by palm texture and geometry.
During the preprocessing step I want to detect fingertips and valley points of the hands. First we must find reference point for the trace bounding integer, after that find valley and fingertips point.
I was wondering if someone is able to help me.
This is my code:
I=imread(palm.jpg);
I=I(:,:,1);
h = fspecial('disk',30);
s = imfilter(I,h,'symmetric');
I1=s(:,:,1)>79;
I4=edge(I1,'canny');
%% find refrense point
s=size(I4);
r=[0,0];
for row=s(1):-1:1
for col=1:s(2)
if I4(row,col)==1
r=[row,col];
break
end
end
if I4(row,col)==1
r=[row,col];
break
end
end
b = bwtraceboundary(I4,[row col],'NW',8);

Independent Component Analysis as Images

I have applied Independent Component Analysis on set of face images using FastICA. I have successfully retrieved independent components and mixing matrix. The values of independent components are in double and I want to display these components as images like available on web, e.g., http://research.ics.aalto.fi/ica/imageica/. I don't know how to show this.
One way you might do this more automatically is with the montage function. Or you can look at subimage. See also this StackOverflow question and answer.
Try the follwing function
function [XX,fh]=dispImgs(X,cols,gap,ihw,fh)
% Courtesy A. Leonardis, D. Skocaj
% see http://vicos.fri.uni-lj.si/danijels/downloads
[M,N]=size(X);
if nargin<2 cols=floor(sqrt(N)); end;
if nargin<3 gap=0; end;
if nargin<4 ihw=[sqrt(M),sqrt(M)]; end;
if nargin<5 fh = figure; end; % new figure
ih=ihw(1);iw=ihw(2);
maxv=max(X(:));
rows=floor(N/cols);
XX=zeros((rows*ih)+(rows-1)*gap,(cols*iw)+(cols-1)*gap)+maxv;
for i=1:N
a=(iw+gap)*mod(i-1,cols)+1;
b=(iw+gap)*mod(i-1,cols)+iw;
c=(ih+gap)*(floor((i-1)/cols))+1;
d=(ih+gap)*(floor((i-1)/cols))+ih;
XX(c:d,a:b)=reshape(X(:,i)',ih,iw);
end;
xxmax=max(XX(:));
xxmin=min(XX(:));
fh = figure(fh);
imshow((XX-xxmin)/(xxmax-xxmin));
axis off;
Example:
X: imsize by N
dispImgs( X, 8, 4, imsize );%show all N images in 8 columns with Gap=4

Get Window Position in HTA

Can i get the current window position in HTA (HTML Application)? which is similar with Me.Top and Me.Left in VB6, but i want it get the pixels number.!?
With JS you can get the position of the topmost window with top.screenLeft and top.screenTop.
Here's a cool way to do it. It's sorta animated
VBScript
Add this to global variables
Dim IntervalMovingWindow
then add this OnLoad routine
Sub Window_OnLoad
moveTo screen.availWidth/2-200 , screen.availHeight/2-100
IntervalMovingWindow= Setinterval ("MoveTheWindow",100)
End Sub
Then Add this Routine for moving windows (animated style)
Sub MoveTheWindow
Dim X,Y
X=top.screenleft
Y=top.screentop
If X<=60 Then
X=0
End If
If Y<=60 Then
Y=0
End If
If X<>0 Then
moveBy -20,0
End If
If Y<>0 Then
moveBy 0,-20
End If
If X=0 And Y=0 Then
moveto 0,0
clearInterval IntervalMovingWindow
End If
End Sub
This may not work if you have an excessively large border. in that case you may need to change -20 in the moveBy to a larger negative number like -30 and the If {X or Y}=60 into a larger positive number like If {X or Y}=80
NOTE don't include the Braces '{}' they just mean that i am talking about both X and the Y conditionals.

First pixel of the image

I just scanned a sample image and I'm trying to detect the first pixel which has a value of "0" in the binary-image.
I used paint to write a text and when i used the following prog, it always catches the bottom most pixel.
clear all;
x=imread('textjay.png');
y=im2bw(x);
height=size(y,1); % row
width=size(y,2); % col
valueoftheindex=0;
pixel_value=0;
for i=1:width
for j=1:height
pixel_value=y(j,i);
if (pixel_value==0)
valueofthewidth=i;
valueofthehieght=j;
break
end
end
end
valueofthewidth
valueofthehieght
imtool(y)
This depends a lot on what you consider to be "the first pixel".
Assuming that you can live with the pixel order that MATLAB assigns you could use
idx = find(y == 0, 1, 'first')
[row_idx, col_idx] = ind2sub(size(y), idx)
For other measures of "firstness" you would have to either transpose the input matrix (the image), or resort to some more refined way of calculation.
And yes, the break will only break the inner loop, as dawe already pointed out.

Resources