Obtain Pixel Shift from Registered Images

조회 수: 14 (최근 30일)
Abigail
Abigail 2025년 5월 7일
편집: Matt J 2025년 5월 9일
Hi all,
I have a series of images taken of 96-well plates that I need to analyze, but they are slightly offset as the plate tends to shift while the images are being taken. I want to create a stack where the wells are in the same position. I have had some good luck with imregister, because normxcorr2 was producing weird results (though maybe that was user error).
My question is: how do I best obtain the pixel shift applied to the moving image from imregister, and can I then scale it to apply to differently sized images? I have used imregtform to obtain the translation matrix, but I had to resize the images to 1/4 of their original size to not make the registration take forever. I need the shift information, however, to align the original images so I can analyze those without data loss.
I hope this makes sense! I appreciate any and all feedback--and if there's something else that may work better I'd be open to trying that out as well. Thanks!

답변 (2개)

Matt J
Matt J 2025년 5월 7일
편집: Matt J 2025년 5월 7일
There's no reason you can't use the tform from imregtform to imwarp the original images, even if the registration was done on cropped or downsampled images. You just need to use imref2d objects to appropriately inform imregtform and imwarp what the pixel sizes are supposed to be.
  댓글 수: 4
Abigail
Abigail 2025년 5월 9일
Unfortunately after copying this and running it with my image stack, the images are not in the same position (ie the wells still move location) when I display SamePositionStack. When I had run pretty much the same code just using imregister, displaying SamePositionStack yielded a much more consistent series where I could just watch the wells. Any clue why?
Matt J
Matt J 2025년 5월 9일
편집: Matt J 2025년 5월 9일
Change to,
shifted_img = imwarp(moving,Rbig,t,'OutputView',Rbig);
Example:
moving=im2double(im2gray(imread('cameraman.tif')));
fixed=imtranslate(moving,[10,15]);
fixed_smaller = imresize(fixed, 0.25);
moving_smaller = imresize(moving, 0.25);
[optimizer,metric] = imregconfig('multimodal');
optimizer.InitialRadius = 0.009;
optimizer.Epsilon = 1.5e-4;
optimizer.GrowthFactor = 1.01;
optimizer.MaximumIterations = 300;
Rbig=imref2d(size(moving));
Rsmall=imref2d(size(moving_smaller),4,4);
t = imregtform(moving_smaller, Rsmall,...
fixed_smaller, Rsmall, ...
'translation',optimizer,metric)
t =
transltform2d with properties: Dimensionality: 2 Translation: [10.0995 14.7921] A: [1.0000 0 10.0995 0 1.0000 14.7921 0 0 1.0000]
shifted_img = imwarp(moving,Rbig,t,'OutputView',Rbig);
figure
imshowpair(moving, fixed,"montage")
figure
imshowpair(shifted_img, fixed,"montage")

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2025년 5월 8일
So I'm assuming you cannot get control over your plate and camera, like have the plate put into a jig to position it precisely every time and have the camera overhead and rigidly fixed to mounts. That's too bad. But to align the images, you can use imregister. It gives you the shifted images directly. You don't need to get a translation vector and then create the registered images from that yourself, so I'm not sure why you want to.
I don't think you can do it without some data loss. I think the shifted image is of the same size as the fixed reference image so some pixels may be shifted out of the frame. I don't believe there is an option to return a larger image so that you do not lose any pixels. However, you should set up your optical system such that any pixels shifted out are not inside any of the 96 wells, so that you're just shifting out border pixels that you don't plan on analyzing anyway.
Registering the images would be useful if you (1) want to make a movie of how the wells are changing over time, or (2) you have a fixed set of circular ROI masks and want to use that for all images instead of trying to determine the array of circles from the image itself (which could be done assuming that at least some of the wells have some contrasting color in them).
  댓글 수: 5
Image Analyst
Image Analyst 2025년 5월 9일
Well if there's nothing there, there's nothing there to find. If it's all black, you can't threshold and find anything brighter than the background. In that case I think you need to redouble your efforts to lock down your plate and camera. Attach your camera to a rigid metal frame. Then for the plate, make an L-shaped metal plate that you can then shove your 96 well plate into the corner of. Make that jig plate bolted down so that it does not change position with respect to the camera's field of view. Then when you shove your 96 well plate into the corner of the L, it should be in precisely the same position, pixel-wise, every single time. It's not hard so get to work on it today. You'll spend less time doing that than the days you're trying to develop custom software to automatically find a shifting plate.
Abigail
Abigail 2025년 5월 9일
Unfortunately it isn't my system and the people who designed it are aware of the issue and are curently working on fixing it--it just isn't there yet. Kind of a complicated/weird situation. I appreciate the suggestions though. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by