I want to plot some (red color)points in the image, my image width and height assume (300 x 300) and I plot (red color) points in Offset(76.2, 75.2) position at image(1,1).
[1]: https://i.stack.imgur.com/mvGt0.jpg
In some cases I need to change the image to (450x 450), but already plot (red color)points are a mismatch.
How to move red color points to (1,1) position of image? how to calculate Offset value.
[2]: https://i.stack.imgur.com/Xua9h.jpg
You have to recalcuate the offsets for the new resolution.
Simply calculate a scale factor by which you can multiply the offsets and redraw the canvas. Pseudocode:
offset = (76.2, 75.2)
scale = 450/300 // 1.5
newOffset = offset * scale //(114.3, 112,5)
Related
I'm trying to draw a polygon using a CustomPainter, this is working fine. Then I would like to draw a 2nd polygon identical to the first underneath it but X times the size. Currently I am transforming the path like:
polygon1 = new Path();
polygon1.addPolygon(polygonPoints, true);
double scale = 1.5;
Matrix4 matrix4 = Matrix4.identity()
..scale(scale,scale,0);
Path polygon2 = Path.from(polygon1)
..transform(matrix4.storage);
However, it seems that polygon2 is also translated which is undesired. I would like it to be perfectly behind the polygon1.
How do I achieve this?
Pictures for reference:
Polygon 1 (green) and Polygon 2 (orange) far away from (0,0) and NOT aligned
Polygon 1 (green) and Polygon 2 (orange) at ~ (0,0) and aligned
I managed to centre the scaled polygon2 by normalizing polygon1 w.r.t. point 0, then scaling the path as above, and finally shifting both paths using the Offset from point 0. Furthermore, the polygon2 needs to be shifted w.r.t to the polygon1 and for this I used polygon1's Rect parameter bottomCenter.
I have background subtracted images as input. The idea is to reduce search areas for person detection by using a smaller search area for the HOG algorithm. The output required is a bounding box around the person and the pixel positions of the box corners.
This is the input image:
This is the required output:
This is what I have tried so far:
x=imread('frame 0080.png');
y=im2bw(x);
s=regionprops(y);
imshow(y);
hold on
for i=1:numel(s)
rectangle('Position',s(i).BoundingBox,'edgecolor','y')
end
This was the output I got:
It looks like you have tried what I have suggested. However, you want the bounding box that encapsulates the entire object. This can easily be done by using the BoundingBox property, then calculating each of the four corners of each rectangle. You can then calculate the minimum spanning bounding box that encapsulates all of the rectangles which ultimately encapsulates the entire object.
I do notice that there is a thin white strip at the bottom of your image, and that will mess up the bounding box calculations. As such, I'm going to cut the last 10 rows of the image before we proceed calculating the minimum spanning bounding box. To calculate the minimum spanning bounding box, all you have to do is take all of the corners for all of the rectangles, then calculate the minimum and maximum x co-ordinates and minimum and maximum y co-ordinates. These will correspond to the top left of the minimum spanning bounding box and the bottom right of the minimum spanning bounding box.
When taking a look at the BoundingBox property using regionprops, each bounding box outputs a 4 element vector:
[x y w h]
x,y denote the top left co-ordinate of your bounding box. x would be the column and y would be the row of the top left corner. w,h denote the width and the height of the bounding box. We would use this and compute top left, top right, bottom left and bottom right of every rectangle that is detected. Once you complete this, stack all of these rectangle co-ordinates into a single 2D matrix, then calculate the minimum and maximum x and y co-ordinates. To calculate the rectangle, simply use the minimum x and y co-ordinates as the top left corner, then calculate the width and height by subtracting the maximum and minimum x and y co-ordinates respectively.
Without further ado, here's the code. Note that I want to extract all of the bounding box co-ordinates in a N x 4 matrix where N denotes the number of bounding boxes that are detected. You would have to use reshape to do this correctly:
% //Read in the image from StackOverflow
x=imread('http://i.stack.imgur.com/mRWId.png');
% //Threshold and remove last 10 rows
y=im2bw(x);
y = y(1:end-10,:);
% //Calculate all bounding boxes
s=regionprops(y, 'BoundingBox');
%// Obtain all of the bounding box co-ordinates
bboxCoords = reshape([s.BoundingBox], 4, []).';
% // Calculate top left corner
topLeftCoords = bboxCoords(:,1:2);
% // Calculate top right corner
topRightCoords = [topLeftCoords(:,1) + bboxCoords(:,3) topLeftCoords(:,2)];
% // Calculate bottom left corner
bottomLeftCoords = [topLeftCoords(:,1) topLeftCoords(:,2) + bboxCoords(:,4)];
% // Calculate bottom right corner
bottomRightCoords = [topLeftCoords(:,1) + bboxCoords(:,3) ...
topLeftCoords(:,2) + bboxCoords(:,4)];
% // Calculating the minimum and maximum X and Y values
finalCoords = [topLeftCoords; topRightCoords; bottomLeftCoords; bottomRightCoords];
minX = min(finalCoords(:,1));
maxX = max(finalCoords(:,1));
minY = min(finalCoords(:,2));
maxY = max(finalCoords(:,2));
% Draw the rectangle on the screen
width = (maxX - minX + 1);
height = (maxY - minY + 1);
rect = [minX minY width height];
% // Show the image
imshow(y);
hold on;
rectangle('Position', rect, 'EdgeColor', 'yellow');
This is the image I get:
I have a .bmp image with a map. What i know:
Height an Width of bmp image
dpi
Map Scale
Image Center's coordinates in meters.
What i want:
How can i calculate some points of image (for example corners) in meters.
Or how can i change a pixel distanse to meters?
What i do before:
For sure i know image center coordinates in pixels:
CenterXpix = Widht/2;
CenterYpix = Height/2;
But what i gonna do to find another corners coordinates. Don't think that:
metersDistance = pixelDistance*Scale;
is a correct equation.
Any advises?
If you know the height or width in both meters and pixels, you can calculate the scale in meters/pixel. You equation:
metersDistance = pixelDistance*Scale;
is correct, but only if your points are on the same axis. If your two points are diagonal from each other, you have to use good old pythagoras (in pseudocode):
X = XdistancePix*scale;
Y = YdistancePix*scale;
Distance_in_m = sqrt(X*X+Y*Y);
I have a grascale image where I want to overlay different colors to different areas that have similar properties (say direction or intensity etc.) I am not referring to a heat map. Rather I have hard coded segmentation code where I have grouped pixels together by their "similarities". Now I want to over lay colors to those pixels.
For example, for a 3x3 pixel pic, say I know that the top row and bottom row are similar group. And the middle row is another group. How can I overlay a red hue with one group and a blue hue with another?
You could make your 3x3x1 grayscale image into a 3x3x3 color image, and then adjust the hue values for the pixels you want.
So say:
GreyImg=[0.2, 0.3, 0.35;...
0.5, 0.6, 0.56;...
0.8, 0.8, 0.85];
%Convert To Color Img
ColorImg(:,:,1)=GreyImg;
ColorImg(:,:,2)=GreyImg;
ColorImg(:,:,3)=GreyImg;
%Add a red hew to top row:
ColorImg(1:1,:,1)=ColorImg(1:1,:,1)+[.2, .2, .2];
%Add a blew hew to top row:
ColorImg(3:3,:,3)=ColorImg(3:3,:,3)+[.2, .2, .2];
imshow(ColorImg);
I have image which size was 600 * 600 and it was displayed on 800 * 800 pixel screen.
The x,y coordinate in which the user look on screen was recorded in an array:
x =[250,300,390,750,760];
y =[120,550,250,130,420];
In other program, I want to plot the x,y coordinate on the 600 * 600 image. The problem is that some of the x,y plot were out of the image (as shown on the picture below) since the coordinate was more that the maximum size of the image (600 * 600).
EDITED:
How to transform/adjust the coordinate of the bigger image (800*800) into the smaller image (600*600) so all x,y coordinate are inside the smaller image (600*600)?
Lets say for example, the coordinate of top left image of the 600*600 inside the image of the 800*800 image is e.g. x = -10, y = 3.
Thanks.
alt text http://img9.imageshack.us/img9/8836/e47184420f.jpg
To get the pixels in image coordinates, you need to know where the bottom left and top right corners of your image were placed on the screen. From that you can both calculate offset and zoom of the image.
%# define some parameters
imageSize = [600 600];
topLeftPixScreen = [200,100]; %# position of the top left image corner in screen pixels
bottomRightPixScreen = [800,750]; %# position of the bottom right image corner in screen pixels
%# transform coordinates
oldX =[250,300,390,750];
oldY =[120,550,250,130,420];
newX = (oldX - topLeftPixScreen(1))/(bottomRightPixScreen(1) - topLeftPixScreen(1) + 1);
newY = (oldY - topLeftPixScreen(2))/(bottomRightPixScreen(2) - topLeftPixScreen(2) + 1);
Having said that, I'd suggest using ginput to select the points with Matlab, since this function directly returns image pixels.
EDIT
If you only have the top left corner, you have to hope that there has not been any scaling - otherwise, there is no way you can transform the points.
With offset only, the above simplifies to
%# define some parameters
imageSize = [600 600];
topLeftPixScreen = [200,100]; %# position of the top left image corner in screen pixels
%# transform coordinates
oldX =[250,300,390,750];
oldY =[120,550,250,130,420];
newX = oldX - topLeftPixScreen(1);
newY = oldY - topLeftPixScreen(2);
It seems that just adjusting the coordinates by the ratio of the screen area and image size would do:
newX = x.*(600/800)
newY = y.*(600/800)