-1

I work with images. I have a button which I use to choose an image of bmp format:

if (OpenPictureDialog1->Execute())
{
    Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
}

The image is displaying in a TImage component. Then I divide the image into sectors and count all of the black dots in each sector. After that, I receive a vector of signs and I normalize it by dividing on the max element in the vector of signs. Then I save the values of normalized vector in a DynamicArray from library <sysdyn.h> and I print the result on a TMemo component:

DynamicArray<double> NormArr1;
NormArr.Length = n;
Memo1->Lines->Add( "Normalized vector is:" );
for (i = 0; i < n; i++)
{
    NormArr[i] = cop[i] / (double) max;
    Memo1->Lines->Add(NormArr[i]);
}
Memo1->Lines->Add( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );

I need to process several images in the same way, but in DynamicArray is saved only the results of processing of one image. So I should click on the button, choose an image and find its normalized vector. Then I should choose another image using the same button, and also find its normalized vector. After that, I need to compare the elements of these vectors.

The most important thing is that I should use only one button and choose not exactly 2 but a lot of images, and compare their normalized vectors. How can I do this? I need the right implementation of self training of images.

Here is my form:

image

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Vorrven
  • 51
  • 6
  • @RemyLebeau can you give an example? – Vorrven Dec 04 '21 at 13:48
  • @RemyLebeau or maybe it's better if i attach a project and if it isn't so hard for you can you fix it exactly in my project? – Vorrven Dec 04 '21 at 13:49
  • 1
    is there something about my previous comment that is unclear to you? What exactly is the problem you are having implementing it? if you don't know how to write a simple function, then this task it probably beyond your current skills. And no, I'm not going to fix your project for you. This is not what this site is about. – Remy Lebeau Dec 04 '21 at 20:13
  • @RemyLebeau yeah, I don't actually understand what do you mean – Vorrven Dec 04 '21 at 21:34
  • 1
    how about using FileList from the win3.11 VCL components or winapi to get the list of files in selected directory (all can be incorporated into dialog box) then feed it to some TListBox where you can select multiple wanted files ... from that process these files instead of using TOpenDialog on each file one by one .... if you want more than just BMP see [opening image file on c++ , PNG , JPEG](https://stackoverflow.com/a/37340970/2521214), You can pack both image and result into single struct/class and create a dynamic list of that struct/class in order to have access to multiple image/result – Spektre Dec 08 '21 at 08:55

1 Answers1

1

I would suggest moving the processing logic into its own function that takes a filename as input and returns a normalized vector as output. Then, when you execute the TOpenPictureDialog, you can loop through the strings in its Files property (make sure the ofAllowMultiSelect flag is enabled on the dialog), passing each selected file to the processing function and saving the results. Then you can compare the saved results as needed.

void __fastcall TMyForm::ButtonClick(TObject* Sender)
{
    if (OpenPictureDialog1->Execute())
    {
        DynamicArray< DynamicArray<double> > AllNormArrs;

        for(int i = 0; i < OpenPictureDialog1->Files->Count; ++i)
        {
            DynamicArray<double> NormArr = normalizeFile(OpenPictureDialog1->Files->Strings[i]);
            // use NormArr as needed...

            AllNormArrs.Length = AllNormArrs.Length + 1;
            AllNormArrs[AllNormArrs.High] = NormArr;
        }

        // compare AllNormArrs elements as needed...
    }
}

DynamicArray<double> __fastcall TMyForm::normalizeFile(String filename)
{
    DynamicArray<double> NormArr;
    // load file, calculate normalized values as needed...
    return NormArr;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you, but I have some questions: normalizeFile is a function where I can do any permutations? Can I load image there. divide it into sectors and receive after all calculations normalized vector by this function? Then I see opening of the file(image) when clicking on button, I don't understand this. Can I show you one part of my code to better explanation? – Vorrven Dec 04 '21 at 23:01
  • 1
    @Vorrven yes, you can do whatever you want in `normalizeFile()` to suit your needs. Writing your own custom functions is a core feature to programming, so I suggest you learn how to do it. You are not going to get very far without it. – Remy Lebeau Dec 05 '21 at 01:06
  • Should I also use there OpenFileDialog? – Vorrven Dec 05 '21 at 08:20