Generation of 2D-ortho-mosaic image in Android - android

I am developing an Android application for image processing. In that, I first need to generate an ortho image by stitching 100+ images together. I have tried it in Android using Bitmap and Canvas. I first did it for 3 images. Is it the right way to generate an ortho or is there any better solution for this? Here is the code that I have used for stitching 3 images:
private void joinImages(File first, File second , File third) throws IOException
{
Bitmap bmp1, bmp2, bmp3;
bmp1 = BitmapFactory.decodeFile(first.getPath());
bmp2 = BitmapFactory.decodeFile(second.getPath());
bmp3 = BitmapFactory.decodeFile(third.getPath());
int height = bmp1.getHeight()+bmp2.getHeight()+bmp3.getHeight();
String height1 = height+"";
Log.d(height1,"heght");
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, bmp1.getHeight(), 0, null);
canvas.drawBitmap(bmp3,bmp1.getHeight()+bmp2.getHeight() , 0, null);
FileOutputStream out = new FileOutputStream("/storage/emulated/0/DCIM/final.jpg");
bmOverlay.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.close();
}
As I am new to Android as well as image processing, I also want to know the difference between image stitching and 2D-orthomosaic generation. Kindly help me with this issue.

Related

android merge several images

I'm trying to merge up to around 200 images. I'm using the following code but on attempting to merge the 3rd image, the first 2 go away and all that I'm shown is only the 3rd image. In reality, when I'm merging the 50th image, I'm really only dealing w/ 2 images: the one that has 49 images merged and the new image to merge. Here is an excert from my hello world project:
InputStream inputStream = getAssets().open(filename);
Bitmap newBitmap = BitmapFactory.decodeStream(inputStream);
Drawable drawable = imageButtonFrameView.getDrawable();
boolean isBitmapDrawable = (drawable instanceof BitmapDrawable);
if (isBitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap existingBitmap = bitmapDrawable.getBitmap();
Paint paint = new Paint();
paint.setAlpha(95);
Bitmap bmOverlay = Bitmap.createBitmap(existingBitmap.getWidth(), existingBitmap.getHeight(), existingBitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(existingBitmap, new Matrix(), paint);
canvas.drawBitmap(newBitmap, 0,0,paint);
newBitmap = bmOverlay;
}
imageButtonFrameView.setImageBitmap(newBitmap);

How do I paste an image onto another image?

I would like to take one image, and then paste it onto another image using Bitmap. (Basically overlaying image 1 on top of image 2 and then being able to save it.)
I've been searching all day for this. Are there any tutorials that show this? I couldn't find any functions in the Android SDK that did this either.
you can combine two bitmaps like this
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
}

Android combine pictures

Hy, I tried to search this but not very much luck
the most similar is this one
http://ketankantilal.blogspot.com/2011/03/how-to-combine-images-and-store-to.html
Anyhow, I'm developing for android.
The question is I have images in png format (or jpg as bmp is quite large for my app).
How can I combine three images from top to bottom.
I do not need to save them on sd just to display them.
Thanks, and sorry if a similar question with answer exists.
You could use a Canvas and then draw each Bitmap (assuming each image is loaded into a Bitmap object) using appropriate top and left offsets.
You would increase the top offset of the next bitmap by the total size of the previously drawn Bitmaps.
Check out http://developer.android.com/reference/android/graphics/Canvas.html
example:
public void stackImages(Context ctx)
{
// base image, if new images have transparency or don't fill all pixels
// whatever is drawn here will show.
Bitmap result = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
// b1 will be on top
Bitmap b1 = Bitmap.createBitmap(400, 200, Bitmap.Config.ARGB_8888);
// b2 will be below b1
Bitmap b2 = Bitmap.createBitmap(400, 200, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(result);
c.drawBitmap(b1, 0f, 0f, null);
// notice the top offset
c.drawBitmap(b2, 0f, 200f, null);
// result can now be used in any ImageView
ImageView iv = new ImageView(ctx);
iv.setImageBitmap(result);
// or save to file as png
// note: this may not be the best way to accomplish the save
try {
FileOutputStream out = new FileOutputStream(new File("some/file/name.png"));
result.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}

capturing image from camera and overlaying another bitmap before we save it

here tempdata is the data captured from camera, savephoto(Bitmap) is a method am using to save the image taken from camera, and it is executing accurately ,,
BUt on [2]
i am overlaying another bitmap ,, and when i am calling the savephoto(p)
it is creating an empty file in the memorycard ...
not saving any image.
how can i overlay the two bitmap on top of each other
[1]File Imgname = Environment.getExternalStorageDirectory();
Bitmap bmp = BitmapFactory.decodeByteArray(tempdata,0,tempdata.length);
imv.setImageBitmap(bmp);
savePhoto(bmp);
[2]Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Bitmap b = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.drawBitmap(bmp, 0,0, null);
canvas.drawBitmap(bmp2, 50, 50, null);
savePhoto(b);
any help will be greatly appreciated
thanx
you can do like this after getting after getting bitmap from camera (assume bitmap1) and your bitmap to overlay on top of bitmap1 (assume bitmap2)
call this overlayMark() with your bitmaps it will return overlay bitmap that is your required bitmap . you can save that bitmap..
private Bitmap overlayMark(Bitmap bmp1, Bitmap bmp2) {
int bh = originalBitmap.getHeight();
int bw = originalBitmap.getWidth();
Bitmap bmOverlay = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, 0,0, null);
return bmOverlay;
}

how to compose(combine) two photo image in android?

Hello
I need to make DRM Image file using two image file.
originally I was use bufferedImage class, but android is not support bufferedImage.
so please help me. how to compose two image in android?
You can do that if you overlay two images. Suppose that bmp1 is bigger one (to be protected), and bmp2 is marker:
private Bitmap overlayMark(Bitmap bmp1, Bitmap bmp2)
{
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, distanceLeft, distanceTop, null);
return bmOverlay;
}
distanceLeft and distanceTop define position of the marker.

Categories

Resources