Combine Two .tiff Files into One Image

32 Ansichten (letzte 30 Tage)
Image Processing Newbie
Image Processing Newbie am 5 Apr. 2021
Kommentiert: DGM am 10 Apr. 2021
Hello MATLAB community! I have two images; one border image and one inside image. Both images have been saved as .tiff files, and I need them to be combined into one image that looks like the one attached in the google drive. I am currently using imfuse(), but after searching through old MATLAB Answers posts, I am not sure if that is the right function to use or if it it the right one how I should be using it. Any help is appreciated, even if it means I must rewrite my fused image function using something other than imfuse. Also attached in the google drive is the output I am currently getting from imfuse. Thank you!
https://drive.google.com/drive/folders/1e9a5Y8_NhgqZQ2D0eqfB_BMjUNjlX__L?usp=sharing
(There is also more code from this file, so if you need it to answer the problem, let me know. But this is the only, in my opinion, relevant function.)
% Find full image
% Just change these two parameters for whatever you save the images as
fused_image = image_fuser(boundary_image.cdata, filtered_image);
function fused_image = image_fuser(boundary,filtered)
fused_image = imfuse(boundary,filtered);
imshow(fused_image);
end
  2 Kommentare
DGM
DGM am 5 Apr. 2021
imfuse() just composites the images. It looks like what you need is to get them registered. You might want to take a look at imregister(), though using it isn't something I'm familiar with.
Image Processing Newbie
Image Processing Newbie am 9 Apr. 2021
imregister() did not work for me. If anyone else has some advice, that would be of the utmost help!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

DGM
DGM am 10 Apr. 2021
Bearbeitet: DGM am 10 Apr. 2021
I'm not familiar with the registration and transformation tools, and I have a feeling that part of the problem is the fact that the images are dissimilar. The registration estimator is going to give nonsense results. I'll leave recommendation of how to use those tools to someone who knows about how to use them.
I don't know what your needs are (accuracy, robustness), or the variability in the images you need to process, but I was able to get it decently registered with more crude methods.
% read images
boundary=imread('boundary1.tif');
interior=imread('filtered1.tif');
% isolate the image from the screenshot
% selected cropborder parameters work for this image, but might not for others
boundary=imbinarize(rgb2gray(boundary));
boundary=cropborder(boundary,[NaN NaN NaN NaN],'automode','deltavar','threshold',0.1);
% trim the edge-connected content from the interior image
% suppress small features (if desired)
interiorfilt=imclearborder(interior);
interiorfilt=bwareaopen(interiorfilt,5,8);
% idk if that fat line on the bottom is needed
% i'm just going to remove it so that it's not in the way
boundary(end-100:end,:)=false;
% dilate the boundary so that it's a single connected group
% remove any remaining speckles
fatbound=imdilate(boundary,strel('disk',5));
fatbound=bwareafilt(fatbound,1);
% invert and close the interior image so that we can find
% its centroid without the influence of the interior features
solidint=imclose(~interior,strel('disk',5));
solidint=bwareafilt(solidint,1);
% calculate offset
c1=struct2array(regionprops(fatbound,'centroid'));
c2=struct2array(regionprops(solidint,'centroid'));
padsize=round(fliplr(c1-c2))
% i'm just going to presume that the offset is always positive.
% if it's not, you'll have to test for that case and then crop instead of pad
interior=padarray(interiorfilt,padsize,0,'pre');
interior=padarray(interior,size(boundary)-size(interior),0,'post');
% combine the images
outpict=interior | boundary;
Of course, this has plenty of obvious limitations, some of which I've noted in the comments. By simply matching centroid locations, I only bothered to pay attention to translation error. If there were a rotation or scale mismatch, that wouldn't get fixed. A similar technique using regionprops() and the 'orientation' metric might be able to be used for correcting rotations. Scale error might similarly be addressed with 'boundingbox'. As the requirements become more demanding, the complexity of this method starts getting unattractive.
Out of convenience for myself, this code uses MIMT tools (namely cropborder)
  2 Kommentare
Image Processing Newbie
Image Processing Newbie am 10 Apr. 2021
Thank you so much for this help! The code you wrote was exactly what I was looking for. There are no rotation or scale mismatches, so this will get the job done. Thank you so much; your toolbox is also fantastic!
Just out of curiosity, what does your "adapthisteqFB" do that normal adapthisteq doesn't? Just curious what your application was for making a new tool. I am dealing with some overexposure on the originals of these images, so I used adapthisteq to the best of my ability but had to settle for some parts of the image not being entirely accurate. Would love to hear more about the specific function you built to see if maybe it would help with my specific dataset!
DGM
DGM am 10 Apr. 2021
Disappointingly, adapthisteqFB() doesn't really do anything that adapthisteq() doesn't. It's essentially identical in functionality and syntax.
There are a lot of tools in the MIMT that are intended to make MIMT independent of the Image Processing Toolbox. Tools like adapthisteqFB() will use the corresponding IPT tool (adapthisteq) if it's available, otherwise they fall back to some internal implementation. In some cases, the internal implementations are slower due to being written in m-code instead of being mex. In the case of adapthisteqFB, the internal implementation has approximately identical performance. There's a list of these tools in the DEPENDENCIES.txt file.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by