That's not an answer.
I am not able to reproduce your issue using this program but I think I don't understand your transformation. My program is :
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
struct ZoomPos {
Point p;
bool newPt;
int zoom;
int typeInter;
bool inter;
};
void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}
void onZoom(int event, int x, int y, int flags, void *userdata)
{
ZoomPos *z=(ZoomPos*)userdata;
if (event== EVENT_LBUTTONDOWN)
{
z->p = Point(x,y);
z->newPt=true;
}
else
z->newPt = false;
}
void MAJInter(int x, void * userdata)
{
ZoomPos *z = (ZoomPos*)userdata;
z->inter=true;
}
int main() {
ifstream fs;
fs.open("pp_sel_00000.fit",ios::binary);
if (!fs.is_open())
{
cout<<"PB";
return 0;
}
fs.seekg(0, ios_base::end);
int nb=fs.tellg();
int nb2=4008*2672*2;
cout<< nb+ -11 * 256 + 64<<" =? "<<nb2<<endl;
fs.seekg(11*256+64, ios_base::beg);
vector<char> v(nb2);
fs.read(v.data(),nb2);
Mat h=(Mat_<double>(3,3)<< -0.99974,- 0.00299,+ 4002.14396, +0.00239,- 0.99964,+ 2673.06210, -0.00000,- 0.00000, 1.00000);
for (int i = 0; i < v.size(); i += 2)
{
swap(v[i],v[i+1]);
}
Mat imgOriginal(2672,4008,CV_16SC1,v.data());
Mat img;
Mat img2;
ZoomPos z;
img=imgOriginal.clone();
resize(img,img,img.size()*2);
warpPerspective(img, img2, h, img.size(), CV_INTER_LANCZOS4);
resize(img2, img, imgOriginal.size());
namedWindow("test", WINDOW_NORMAL);
int code=0;
imshow("test",img);
z.p =Point(0,0);z.newPt = false; z.zoom = 1;z.inter=false;z.typeInter= CV_INTER_LANCZOS4;
AjouteGlissiere("Interpolation", "test", 0, CV_INTER_LANCZOS4, CV_INTER_LANCZOS4, &z.typeInter,MAJInter,&z);
setMouseCallback("test",onZoom,&z);
Mat x;
bool modifZoom=false;
Ptr<Mat> lutRND;
if (!lutRND)
{
RNG ra;
lutRND = makePtr<Mat>(256, 1, CV_8UC3);
ra.fill(*lutRND, RNG::UNIFORM, 0, 256);
}
while (code != 27)
{
code = waitKey(10);
switch (code){
case '+' :
if (z.zoom < 16)
{
modifZoom=true;
z.zoom += 1;
}
break;
case '-' :
if (z.zoom>=2)
{
modifZoom = true;
z.zoom -= 1;
}
break;
}
if (z.inter)
{
img = imgOriginal.clone();
resize(img, img, img.size() * 2);
warpPerspective(img, img2, h, img.size(), z.typeInter);
resize(img2, img, imgOriginal.size());
imshow("test", img);
}
if (z.newPt || z.inter || modifZoom)
{
Rect r(z.p.x-50, z.p.y - 50,100,100);
if (r.tl().x<0)
r.x = 0;
if (r.tl().y<0)
r.y = 0;
resize(img(r),x,Size(),z.zoom,z.zoom);
Mat x3;
x=x/256;
(x).convertTo(x3,CV_GRAY2BGR);
applyColorMap(x3,x3, *lutRND.get());
imshow("zoom",x3);
z.inter= false;
modifZoom=false;
waitKey(10);
cout<<"-->\n";
}
}
waitKey();
}
Try to convert your image CV_32F before warp
Could it be as simple that this solution ? Ok I have to find a way to convert data. Thank you.
use convertTo function
Yes and to convert back to 16U: out.convertTo(out, CV_16UC3, 65535.0); ?
yes and no. using Lanczos4, I think you can have values greater than 65535 and less than 0. convertTo(out, CV_16UC3, 65535.0) : values will be saturate why not? you have to choose saturate or use min max values to convert
It looks like artifacts are almost gone like that !!!
Oh no. Sorry. Changes are not really visible.
The probleme is that on linear images, typical undershoot artifacts are composed of one or a few very dark pixels around bright structures such as stars. I would need an algorithm to prevent generation of visible undershoot artifacts. If it exists of course.
The problem is that on linear images, typical undershoot artifacts are composed of one or a few very dark pixels around bright structures such as stars. I would need an algorithm to prevent generation of visible undershoot artifacts in addition to the Lanczos interpolation. If it exists of course.
Can you post one image and give perpersctive parameters .? i cannot reproduce your issue using 8 bits image