This class hosts calibrated texture & swatches infos
Inheritance: IDisposable
Exemple #1
0
            public ImageUtility.float4 Location = new ImageUtility.float4();                            // The location (in UV space) where the swatch color was taken (XY=Top Left Corner, ZW=Bottom Right Corner)
            public override void    Save(CalibratedTexture _Owner, XmlElement _SwatchElement)
            {
                base.Save(_Owner, _SwatchElement);

                _Owner.SetAttribute(_SwatchElement, "SampleTopLeft", (new ImageUtility.float2(Location.x, Location.y)).ToString());
                _Owner.SetAttribute(_SwatchElement, "SampleBottomRight", (new ImageUtility.float2(Location.z, Location.w)).ToString());
            }
            public ImageUtility.float3 xyY; // The color used to build the swatch

            #endregion Fields

            #region Methods

            public virtual void Save( CalibratedTexture _Owner, XmlElement _SwatchElement )
            {
                ImageUtility.float4	XYZ = new ImageUtility.float4( ImageUtility.ColorProfile.xyY2XYZ( xyY ), 1.0f );
                ImageUtility.float3	RGB = (ImageUtility.float3) Texture.Profile.XYZ2RGB( XYZ );
                _Owner.SetAttribute( _SwatchElement, "xyY", xyY.ToString() ).SetAttribute( "RGB", RGB.ToString() );
            }
            public ImageUtility.float4 Location = new ImageUtility.float4(); // The location (in UV space) where the swatch color was taken (XY=Top Left Corner, ZW=Bottom Right Corner)

            #endregion Fields

            #region Methods

            public override void Save( CalibratedTexture _Owner, XmlElement _SwatchElement )
            {
                base.Save( _Owner, _SwatchElement );

                _Owner.SetAttribute( _SwatchElement, "SampleTopLeft", (new ImageUtility.float2( Location.x, Location.y )).ToString() );
                _Owner.SetAttribute( _SwatchElement, "SampleBottomRight", (new ImageUtility.float2( Location.z, Location.w )).ToString() );
            }
Exemple #4
0
        private void buttonLoadImage_Click( object sender, EventArgs e )
        {
            string	OldFileName = GetRegKey( "LastImageFilename", m_ApplicationPath );
            openFileDialogSourceImage.InitialDirectory = System.IO.Path.GetDirectoryName( OldFileName );
            openFileDialogSourceImage.FileName = System.IO.Path.GetFileName( OldFileName );

            if ( openFileDialogSourceImage.ShowDialog( this ) != DialogResult.OK )
             				return;

            SetRegKey( "LastImageFilename", openFileDialogSourceImage.FileName );

            try
            {
                // Load
                System.IO.FileInfo	ImageFileName = new System.IO.FileInfo( openFileDialogSourceImage.FileName );
                ImageUtility.Bitmap	NewBitmap = new ImageUtility.Bitmap( ImageFileName );

                // Safely assign once loaded
                m_ImageFileName = ImageFileName;
                m_BitmapXYZ = NewBitmap;

                this.Text = APP_TITLE + " (" + ImageFileName.Name + ")";

                // Setup camera shot info if it exists
                if ( m_BitmapXYZ.HasValidShotInfo )
                {
                    groupBoxCameraShotInfos.Enabled = false;
                    floatTrackbarControlISOSpeed.Value = m_BitmapXYZ.ISOSpeed;			floatTrackbarControlISOSpeed.SimulateValueChange();	// So we get notified even if value is the same as default slider value
                    floatTrackbarControlShutterSpeed.Value = m_BitmapXYZ.ShutterSpeed;	floatTrackbarControlShutterSpeed.SimulateValueChange();	// So we get notified even if value is the same as default slider value
                    floatTrackbarControlAperture.Value = m_BitmapXYZ.Aperture;			floatTrackbarControlAperture.SimulateValueChange();	// So we get notified even if value is the same as default slider value
                    floatTrackbarControlFocalLength.Value = m_BitmapXYZ.FocalLength;	floatTrackbarControlFocalLength.SimulateValueChange();	// So we get notified even if value is the same as default slider value
                }
                else
                    groupBoxCameraShotInfos.Enabled = true;

                // Clear calibrated texture & UI
                if ( m_Texture != null )
                    m_Texture.Dispose();
                m_Texture = null;
                resultTexturePanel.CalibratedTexture = null;
                buttonSaveCalibratedImage.Enabled = false;

                foreach ( CustomSwatch S in m_CustomSwatches )
                {
                    S.m_CheckBox.Checked = false;
                    S.m_Panel.BackColor = Color.DimGray;
                }

                // Prepare database with new camera shot infos
                PrepareDatabase( false );

                // Re-apply white reflectance reference if it's adapted to the
                if (	Math.Abs(m_CalibrationDatabase.PreparedForISOSpeed - m_WhiteReflectanceISOSpeed) < 1e-6f
                    && Math.Abs(m_CalibrationDatabase.PreparedForShutterSpeed - m_WhiteReflectanceShutterSpeed) < 1e-6f
                    && Math.Abs(m_CalibrationDatabase.PreparedForAperture - m_WhiteReflectanceAperture) < 1e-6f )
                {
                    m_CalibrationDatabase.WhiteReflectanceReference = m_WhiteReflectanceReference;
                }
                UpdateWhiteReflectanceUI();			// If the shot infos are different from the ones from which the white reflectance was picked then the values got reset so update UI

                RebuildImage();						// Finally, rebuild the image and show it in the output panel
                outputPanel.ResetCropRectangle();	// Previous crop rectangle is not valid anymore
            }
            catch ( Exception _e )
            {
                MessageBox( "An error occurred while loading the image:\r\n\r\n", _e );
            }
        }
Exemple #5
0
        private void buttonCapture_Click( object sender, EventArgs e )
        {
            if ( m_BitmapXYZ == null )
            {	// No image loaded you moron!
                MessageBox( "Can't capture as no image is currently loaded!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
                return;
            }
            if ( !PrepareDatabase() )
                return;

            //////////////////////////////////////////////////////////////////////////
            // Prepare parameters
            CalibratedTexture.CaptureParms	Parms = new CalibratedTexture.CaptureParms() {
                SourceImageName = m_ImageFileName.FullName,

                ISOSpeed = floatTrackbarControlISOSpeed.Value,
                ShutterSpeed = floatTrackbarControlShutterSpeed.Value,
                Aperture = floatTrackbarControlAperture.Value,

                CropSource = !outputPanel.IsDefaultCropRectangle,
                CropRectangleCenter = new ImageUtility.float2( outputPanel.CropRectangeCenter.x, outputPanel.CropRectangeCenter.y ),
                CropRectangleHalfSize = new ImageUtility.float2( outputPanel.CropRectangeHalfSize.x, outputPanel.CropRectangeHalfSize.y ),
                CropRectangleRotation = outputPanel.CropRectangeRotation,

                UseModeInsteadOfMean = checkBoxUseMeanMode.Checked,
            };

            //////////////////////////////////////////////////////////////////////////
            // Go!
            try
            {
                CalibratedTexture	Tex = new CalibratedTexture();
                Tex.Capture( m_BitmapXYZ, m_CalibrationDatabase, Parms );
                m_Texture = Tex;

                // Use the form's swatch panels as default swatch size
                m_Texture.SwatchWidth = panelCustomSwatch0.Width-2;
                m_Texture.SwatchHeight = panelCustomSwatch0.Height-2;

                // Update UI
                resultTexturePanel.CalibratedTexture = m_Texture;
                buttonSaveCalibratedImage.Enabled = true;
                labelCaptureWhiteReflectanceCorrection.Text = "White Correction " + Tex.WhiteReflectanceCorrectionFactor.ToString( "G4" );
                labelCaptureSpatialCorrectionStatus.Text = "Spatial Correction is " + (Tex.SpatialCorrectionEnabled ? "enabled" : "disabled");

                m_SwatchMin.m_xyY = m_Texture.SwatchMin.xyY;
                m_SwatchMin.UpdateSwatchColor();
                m_SwatchMax.m_xyY = m_Texture.SwatchMax.xyY;
                m_SwatchMax.UpdateSwatchColor();
                m_SwatchAvg.m_xyY = m_Texture.SwatchAvg.xyY;
                m_SwatchAvg.UpdateSwatchColor();

                foreach ( CustomSwatch S in m_CustomSwatches )
                    S.UpdateSwatchColor();
            }
            catch ( Exception _e )
            {
                MessageBox( "An error occurred during capture:\r\n\r\n", _e );
            }
        }
Exemple #6
0
            public ImageUtility.Bitmap Texture;                                                                 // The bitmap generated from the swatch color

            public virtual void     Save(CalibratedTexture _Owner, XmlElement _SwatchElement)
            {
                ImageUtility.float4 XYZ = new ImageUtility.float4(ImageUtility.ColorProfile.xyY2XYZ(xyY), 1.0f);
                ImageUtility.float3 RGB = (ImageUtility.float3)Texture.Profile.XYZ2RGB(XYZ);
                _Owner.SetAttribute(_SwatchElement, "xyY", xyY.ToString()).SetAttribute("RGB", RGB.ToString());
            }