what is the fastest way to rotate a bmp image in C? - bmp

I'm creating a photo edit app and i was wondering..How can I rotate a bmp pic fast? I mean what's the quickest piece of code to rotate it by 90 degrees?
Thank you

I think it boils down to rotating a matrix, or a 2 dimensional matrix.
Which means that you have to do O(n * m) operations, when the image has dimension n * m.

Paint has a few pieces of code that will do the things required pretty fast, depending on your dexterity.

Related

Which kind of filtering is used in SPCImage for binning?

I was wondering if anyone knows which kind of filter is applied by SPCImage from the Becker & Hickl system.
I am taking some FLIM data with my system and I want to create the lifetime images. For doing so I want to bin my images in the same way as it does SPCImage, so I can increase my SN ratio. The binning goes like 1x1, 3x3, 5x5, etc. I have created the function for doing a 3x3 binning, but each time it gets more complicated...
I want to do it in MATLAB, and maybe there is already a function that can help me with this.
Many thanks for your help.
This question is old, but for anyone else wondering: You want to sum the pixels in an (2M+1) x (2M+1) neighborhood for each plane (M integer). So I am pretty sure you can go about the problem by treating it like a convolution.
#This is your original 3D SDT image
#I assume that you have ordered the image with spatial dimensions along the
#first and second and the time channels are the third dimension.
img = ... #<- your 3D image goes here
#This describes your filter. M=1 means take 1 a one pixel rect around your
#center pixel and add the values to your center, etc... (i.e. M=1 equals a
#total of 3x3 pixels accumulated)
M=2
#this is the (2D) filter for your convolution
filtr = ones(2*M+1, 2*M+1);
#the resulting binned image (3D)
img_binned = convn(img, filtr, 'same');
You should definitely check the result against your calculation, but it should do the trick.
I think that you need to test/investigate image filter functions to apply to this king of images Fluorescence-lifetime imaging microscopy.
A median filter as showing here is good for smoothering things. Or a weihgted moving average filter where applied to the image erase de bright spots and only are maintained the broad features
So you need to review of the digital image processing in matlab

Find actual height of image from screen height with camera angle distortion

If my phone camera is at a known height on my phone and it takes a picture from a known distance, how can I find out the actual height of an object at the bottom of the picture, considering that the camera is taking the photo from a top angle?
This question talks of a similar problem, but the answers haven't taken camera angle and height into account.
Here's a diagram of the setup -
h is the actual height of the yellow box in front of the blue screen.
This is the image captured by the camera -
How can I find h, given h' on the image? Assume the focal length of the camera is known.
Assuming you know the calibration matrix K, here is a solution that I find simpler than calculating angles. Choose the points p1=(x,y) and p2=(r,s) as indicated in the figure above. Since you say that you know the distance from the camera to the object, that means you know the depth d of these points in camera coordinates, and
Q1=inverse(K)*p1*d
Q2=inverse(K)*p2*d
give you the corresponding points on the cube in camera coordinates. Now the height you seek is simply
abs(Q1-Q2)
Hope that helps.
Edit: Here's a quick explanation about the calibration matrix. When using the pinhole camera model, a 3d point P can be reprojected in the image plane via the multiplication KP where K is (assuming square pixels) the matrix
f 0 a
0 f b
0 0 1
where f is the focal length expressed in terms of pixel size, and [-a,-b]^t is the center of the image coorrdinates system (expressed in pixels). For more info, you can just goolge "intrinsic camera parameters", or for a quick and dirty explanation look here or here. And maybe my other answer can help?
Note: In your case since you only care about depth, you do not need a and b, you can set them to 0 and just set f.
PS: If you don't know f, you should look into camera calibration algorithms (there are auto-calibrating methods but as far as I know they require many frames and fall into the domain of SLAM/SFM). However, I think that you can find pre-computed intrinsic parameters in Blender for a few known smartphone models, but they are not expressed in the exact manner presented above, and you'll need to convert them. I'd calibrate.
I must be missing something, but I think this is quite easy (based on your assumptions, which include doing some type of image processing to detect the front and bottom edges of your object in order to get h') Keep in mind that you are also assuming that your distance from the top of the object to your camera is the same as from the bottom of your object to your camera. (at greater distances this becomes moot, but at close ranges, the skew can actually be quite significant)
The standard equation for distance:
dist = (focalDist(mm) * objectRealHeight(mm) * imageHeight(pix) ) / ( objectHeight(pix) * sensorHeight(mm) )
You can re-arrange this equation to solve for objectRealHeight since you know everything else...

Rotate Circular Images

Hello I'm going to do text detection on circular images.
After some preprocessing I do polar to cartesian transformation on images
this is example of my real image
after doing p2c transformation my images become like
but since my images come in a different angles sometimes p2c transformation cut out my characters
I think I need to do proper rotation before p2c transformation.
my question is what kind of rotation method is proper for this situation? or should I start p2c transformation based on histogram values ? or what kind of other ways would you guys suggest me?
thanks
I suggest you do your polar to cartesian transformation and analyse your resulting image X. You can find you letters by summing all values along the x dimension and using a threshold to detect if there is a letter or not:
y = sum(X,1);
th = (max(y) + min(y)) / 2;
letters = y < th;
Now you can find out if there is a letter at the border of the image and shift the image if this is the case.
if sum(letters([1:10,end-10:end]))
X = circshift(X,[0,10]);
end
Of course you can't be sure that there is no letter at the border now, so better loop this procedure until no letter is found at the border.

How to know rotation degree in matlab for a rotated image?

I would like to :
step 1) Rotate an image with 20 degrees using this code rotatedImage = imrotate(originalImage, 20);.
step 2) calculate degree rotation used in step 1 based only on the rotated image if it possible or based on rotated image and the original image.
there is any function in matlab could do the step 2 or a proposition to do that?
This example shows one way to perform step 2:
A = 'peppers.jpg';
img = im2double(imread(A));
img_r=imrotate(img,20,'nearest','crop'); % <-- this is the distorted image
% rotated 20 deg
xopt = fminsearch(#(x) imr(x,img_r,img), 10); % <-- start with 10 deg as guess
where imr is the function
function obj= imr(x,img1,img2);
img1_r = imrotate(img1,x,'nearest','crop');
obj = sum((img2(:)-img1_r(:)).^2);
The function wraps imrotate, generating an objective function to minimize so that it can be used by fminsearch.
This shows the original, distorted, and reversed image (with angle determined as above):
Note the limitations: the rotated images are cropped so that a point-by-point comparison is possible during computation of the objective function.
This is probably not the absolutely best way to do this, as I imagine that there are morphological algorithms designed to answer your specific question in a more general way. Still it worked.
You might want to check this. I had used Fourier-Mellin transform to retrieve rotation. Its accurate up to 1 degree. I think you will have to invest some time + don't forget to check some papers on Fourier-Mellin transform

matlab: correct approach to add geometrical objects to image

please help with Matlab beginner challenge
i need to create an image with few geometrical objects (circles,
ellipses) and then to apply some projective transforms
my problem is that i cant understand how to actually "draw" on image
image is AFAIU generally defined as [X;Y;3] matrix,
functions as SCIRCLE1 can compute/return collection of points
representing circle, but the problem is that points are not discrete ,
coordinates are real numbers and not pixels
how can i recompute the scircle output to be valid in image
coordinates system ? i.e. how can i "pixelize" it?
thanks for your attention, i really missing some basic concept and
will appreciate your help
John
well, below is an answer i received on Matlab newsgroups
BOTTOM LINE-no built-in way in Matlab
======================================
'getframe' can be used to merge axes even though it is more commonly used to create movie frames.
MATLAB is really weak in this area. There are some primitive
functions for drawing into the overlay (such as rectangle() if you
want to draw a circle, and line() if you want to draw a line) but no
real way that I know of to draw right into the underlying image. So
you have to use "tricks" such as getframe and then apply logical
operations. And you have to be careful with that since I think when
it gives you the rasterized version of the overlay it might be the
size of the image on the screen, not the true original matrix size of
the underlying image (I'd have to recheck this).
full thread here : http://www.mathworks.com.au/matlabcentral/newsreader/view_thread/261232
I found this example which give you a easy way to put simple geometrical object onto pictures.
Read the input image.
I = imread('cameraman.tif');
Define the rectangle dimensions as [x y width height].
rectangle = int32([10 10 30 30]);
Draw the rectangle and display the result.
J = step(shapeInserter, I, rectangle);
imshow(J);
see this link
by the way..
I didn't get you point about points not being discrete and images being a matrix. The way I see it. It much the same. you could try to explain it more in depth ?
The insertShape function in the Computer Vision System Toolbox is what you need. It lets you draw rectangles, circles, and polygons into the image.
There is also insertText, insertMarker, and insertObjectAnnotation.