OpenCV imwrite enregistrement complet noir jpeg

J'ai fait quelques pré traitement de vdf , et je suis en train d'enregistrer cette image par imwrite.

Mon image recadrée a cette information

output.type()           5   

output.channels()       1

output.depth()          5

Mais a chaque fois que je l'enregistre, donne du noir de sortie. J'ai vérifié les vieux threads existants de stackoverflow mais tout ne semble pas travailler pour moi.
par exemple
OpenCV2.3 imwrite enregistre noir image

J'ai essayé de nombreuses conversions de couleurs et de la profondeur de la conversion en tant que bien, mais je ne sais pas pourquoi il ne fonctionne pas.

std::vector<int> qualityType;
qualityType.push_back(CV_IMWRITE_JPEG_QUALITY);
qualityType.push_back(90);

Mat out1,out2;

cv::cvtColor(output, out1, CV_GRAY2BGR);
//out1.convertTo(out2,CV_8U,1./256); //i tried this too 
cv::imwrite("dft1.jpg",out1,qualityType); //tried even using quality type

imshow affichage de cette image, bien que le problème vient quand je l'enregistre en.

s'il vous plaît aider

[EDIT] Peut-être que mon dft classe que j'ai fait a un problème parce que j'ai chaque fois que je utiliser dft fonction de la sortie ne peut travailler qu'avec inshow mais pour les sauver, il ne fonctionne pas.

CDftRidgeAnalyses::CDftRidgeAnalyses(void)
{
}
CDftRidgeAnalyses::~CDftRidgeAnalyses(void)
{
}
Mat CDftRidgeAnalyses::GetRidgeAnalyses(Mat inpGray)
{
Mat img = inpGray;
int WidthPadded=0,HeightPadded=0;
WidthPadded=img.cols*2;
HeightPadded=img.rows*2;
int M = getOptimalDFTSize( img.rows );
//Create a Gaussian Highpass filter 5% the height of the Fourier transform
double db  = 0.05 * HeightPadded;
Mat fft = ForierTransform(img.clone(),HeightPadded,WidthPadded);
Mat ghpf = CreateGaussianHighPassFilter(Size(WidthPadded, HeightPadded), db);
Mat res;
cv::mulSpectrums(fft,ghpf,res,DFT_COMPLEX_OUTPUT);
Mat mag  = GetDftToImage(res,img);
int cx = mag.cols/2;
int cy = mag.rows/2;
cv::Mat croped = mag(cv::Rect(0,0,cx, cy));
cv::threshold(mag, mag, 0.019, 1, cv::THRESH_BINARY);
Mat bgr;
cvtColor(mag,bgr,CV_GRAY2RGB);
//imshow("XXX",bgr);
//imshow("croped", croped);
//imshow("img",img);
//
//cv::waitKey();
return croped;
}
Mat CDftRidgeAnalyses::ForierTransform(Mat inpGray,int M,int N)
{
Mat img = inpGray;
int i = img.channels();
Mat padded;
Mat img2;
img.convertTo(img2,CV_64F,1./255);
copyMakeBorder(img2, padded, 0, M - img2.rows, 0, N - img2.cols, BORDER_CONSTANT, Scalar::all(0));
Mat element1 = Mat_<float>(padded);
Mat element2 = Mat::zeros(padded.size(), CV_32F);
Mat planes[] = {element1, element2};
Mat complexImg;
merge(planes, 2, complexImg);
dft(complexImg, complexImg ,0, img.rows);
//printMat(complexImg);
return complexImg;
}
double CDftRidgeAnalyses::pixelDistance(double u, double v)
{
return cv::sqrt(u*u + v*v);
}
double CDftRidgeAnalyses::gaussianCoeff(double u, double v, double d0)
{
double d = pixelDistance(u, v);
return 1.0 - cv::exp((-d*d) / (2*d0*d0));
}
cv::Mat CDftRidgeAnalyses::CreateGaussianHighPassFilter(cv::Size size, double cutoffInPixels)
{
Mat ghpf(size, CV_32F);
cv::Point center2((size.width*0.80), size.width/2);
//cv::Point center2(0,0);
for(int u = 0; u < ghpf.rows; u++)
{
for(int v = 0; v < ghpf.cols; v++)
{
ghpf.at<float>(u, v) = gaussianCoeff(u - center2.x, v - center2.y, cutoffInPixels);
}
}
Mat bmp;
int channels = ghpf.channels();
int type = ghpf.type();
int depth = ghpf.depth();
cv::cvtColor(ghpf,bmp,CV_GRAY2RGB); 
cv::cvtColor(ghpf,bmp,CV_GRAY2BGRA); 
//imshow("XXX",bmp);
int cx = ghpf.cols/2;
int cy = ghpf.rows/2;
Mat tmp;
int iExactright =  (size.width*0.59);
int iExactbottom = (size.height*0.86);
//full   Mat q0(ghpf, Rect(69,10,400,290));
// Mat whiteq(ghpf, Rect(0,390,270,330));
int iMainleft=0, iMainright=0;
int iMainBottom=0,iMainTop=0;
Mat Quad;
Mat ql(ghpf, Rect(190,0,270,330));
/** Make the rectangle on middle default filter with respect to top right angle**/
iMainleft=(size.width*0.111);
iMainright=(size.width*0.402);
iMainTop=(size.height*0.484);
iMainBottom = (size.height*0.155);
Quad = ghpf(Rect(iMainleft,iMainTop,iMainright+6,iMainBottom));
Mat qTopRight(ghpf, Rect(iExactright,0, iMainright+6, iMainBottom));
Quad.copyTo(qTopRight);
/** Make the rectangle on middle default filter with respect to top left angle**/
iMainright=(size.width*0.402);
Quad = ghpf(Rect(300,iMainTop,300,iMainBottom));
Mat qTopLeft(ghpf, Rect(0,0, 300, iMainBottom));
Quad.copyTo(qTopLeft);
/** Make the rectangle on middle default filter with respect to bottom left angle**/
iMainTop = iMainTop-iMainBottom;
iExactbottom = size.height - iMainBottom;
Quad = ghpf(Rect(300,iMainTop,300,iMainBottom));
Mat qBottomLeft(ghpf, Rect(0,iExactbottom, 300, iMainBottom));
Quad.copyTo(qBottomLeft);
/** Make the rectangle on middle default filter with respect to bottom right angle**/
iMainleft=(size.width*0.111);
iMainright=(size.width*0.402);
Quad = ghpf(Rect(iMainleft,iMainTop,iMainright+6,iMainBottom));
Mat qBottomRight(ghpf, Rect(iExactright,iExactbottom, iMainright+6, iMainBottom));
Quad.copyTo(qBottomRight);
//remove middle rectangle [ circle ] 
iMainright=(size.width*0.402);
Quad = ghpf(Rect(0,iMainTop+iMainTop,size.width,iMainBottom+iMainBottom-130));
Mat qMiddle(ghpf,Rect(0,iMainTop+150,size.width,iMainBottom+iMainBottom-130));
Quad.copyTo(qMiddle);
qMiddle =ghpf(Rect(0,iMainTop-10,size.width,iMainBottom+iMainBottom-130));
Quad.copyTo(qMiddle);
normalize(ghpf, ghpf, 0, 1, CV_MINMAX);
/*Mat x;
cv::resize(ghpf,x,cv::Size(400,700));
imshow("fftXhighpass2", x);*/
Filter = ghpf;
Mat padded;
copyMakeBorder(ghpf, padded, 0, size.height - ghpf.rows, 0, size.width - ghpf.cols, BORDER_CONSTANT, Scalar::all(0));
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
Mat complexImg;
merge(planes, 2, complexImg);
return complexImg;
}
Mat CDftRidgeAnalyses::GetDftToImage(Mat res,Mat orgImage)
{
idft(res,res,DFT_COMPLEX_OUTPUT,orgImage.rows);
Mat padded;
copyMakeBorder(orgImage, padded, 0,orgImage.rows, 0, orgImage.cols, BORDER_CONSTANT, Scalar::all(0));
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
split(res, planes);
magnitude(planes[0], planes[1], planes[0]);
Mat mag = planes[0];
mag += Scalar::all(1);
// log(mag, mag);
//crop the spectrum, if it has an odd number of rows or columns
mag = mag(Rect(0, 0, mag.cols & -2, mag.rows & -2));
normalize(mag, mag, 1, 0, CV_MINMAX);
return mag;
}

La sortie que je suis en train de la sauver est de

Mat org = imread("4.png",CV_LOAD_IMAGE_GRAYSCALE);
Mat re;
resize(org,re,cv::Size(311,519));
Mat xyz = CDftRidgeAnalyses::GetRidgeAnalyses(re);
cv::imwrite("dft1.jpg",xyz);

ici la matrice xyz a ces valeurs

output.type()           5   

output.channels()       1

output.depth()          5

J'espère que vous les gars maintenant peut m'aider à mieux... peut-être après la converion de filtre complexe je suis de perdre quelques points????

Une remarque préliminaire: vous êtes en train d'écrire un fichier bmp dans votre exemple de code, tout en offrant jpeg paramètres. Avez-vous vérifié que le premier ?
j'ai même vérifié avec bmp sans l'aide du paramètre ainsi , auparavant, j'ai été vérifier avec jpg mais il n'a pas de travail pour eux deux. Oui, par erreur, j'ai oublié de supprimer la qualité type, mais ce n'est pas la question. Image venir encore et toujours que le noir quand je l'enregistre en.
Il serait utile si vous incluez ce que les valeurs entières .type(), .profondeur() représentent. Est-il une variable point de l'image(valeurs 0-1). Si oui, êtes-vous d'appliquer la bonne mise à l'échelle avant de l'enregistrer?
J'ai essayé exactement le même code que toi, sauf que je suis en train de lire un fichier de mon disque, puis écrire avec votre échantillon ci-dessus. Il a travaillé comme un charme (opencv 2.4, mac os). Vous devriez vérifier à nouveau votre image d'entrée (type, valeurs...).
Votre profondeur de 16 bits float. imwrite prend 8bit, sauf pour jpeg2000 fichiers.

OriginalL'auteur wolvorinePk | 2012-05-13