Skip to content

Commit

Permalink
Fixing 0-255 scaling bug while maintaining float tif compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Eurybiadan committed Jul 24, 2018
1 parent 8856e1a commit 3d5f19a
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions SupportFunctions/AOMosiacAllMultiModal.m
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,18 @@
loadednames{m} = name;

if size(im_,3) == 2
%add to combined image
nonzero = im_(:,:,2)>0;
im_ = im_(:,:,1);
else
nonzero = im_>0;
end

if(isa(im,'double') || isa(im,'single'))
im_(:,:,1) = uint8(round(im_*255));
im_(:,:,2) = uint8(round(nonzero*255));
im_(:,:,2) = uint8(round(nonzero*255));
else
im_ = im_(:,:,1);
%add to combined image
nonzero = im_>0;
im_(:,:,1) = uint8(round(im_*255));
im_(:,:,2) = uint8(round(nonzero*255));
im_(:,:,1) = uint8(round(im_));
im_(:,:,2) = uint8(round(nonzero*255));
end

saveName=[name,'_aligned_to_ref',num2str(i),'_m',num2str(m)];
Expand All @@ -629,7 +630,7 @@
end
end

save tmp.mat;
% save tmp.mat;
%%

for m = 1:MN
Expand Down Expand Up @@ -660,39 +661,27 @@

%save each individually transformed image
[pathstr,name,ext] = fileparts(char(imageFilename{m,n})) ;


%we check the original type of the image and save accordingly

if size(im_,3) == 2
%add to combined image
nonzero = im_(:,:,2)>0;
im_ = im_(:,:,1);
imCombined(nonzero) = im_(nonzero);
im_(:,:,1) = uint8(round(im_));
im_(:,:,2) = uint8(round(nonzero*255));
else
im_ = im_(:,:,1);
nonzero = im_>0;
imCombined(nonzero) = im_(nonzero);
im_(:,:,1) = uint8(round(im_));
im_(:,:,2) = uint8(round(nonzero*255));
else
nonzero = im_>0;
end

%add to combined image
imCombined(nonzero) = im_(nonzero);

%save
saveFileName=[name,'_aligned_to_ref',num2str(i),'_m',num2str(m),'.tif'];

if(isa(im,'double') || isa(im,'single'))%if input was floating point, save as single
im_(:,:,2) = nonzero;
saveTifDouble(single(im_),outputDir,saveFileName);
else%else save as uint8
%convert if output file is currently floating,
if (isa(im_,'double') || isa(im,'single'))
im_(:,:,1) = uint8(round(im_*255));
im_(:,:,2) = uint8(round(nonzero*255));
end
%otherwise save
im_(:,:,1) = uint8(round(im_));
im_(:,:,2) = uint8(round(nonzero*255));

saveTif(im_,outputDir,saveFileName);
end

Expand Down

0 comments on commit 3d5f19a

Please sign in to comment.