Binary image from a plot

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Binary image from a plot

marcasser
Hi, 

I'm struggling with an images comparison task and I would appreciate your tips.

The software I’m doing, prints some plots that I save as .bmp and with -mono and -bestfit parameters. When I read them with “imread” function, I can see that it’s an indexed image and the matrix contains values [0 255]. I would like to convert it to binary but without using the “image” package. 
(Yes, I know that this sounds weird but I would like to find a solution without using it, if possible. It’s due to some incompatibilities with some computers in the lab which cannot be updated to the last Octave version nor installing packages.)

I have to compare images to see the similarity and the easiest way for me it’s to do it with binary values. 

Any tips that you could give me? I’m stuck here…

Thanks!

Maria


Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

Andreas Weber-6
Hi Maria,

Am 07.07.20 um 12:37 schrieb Maria Jose Casas Serrano:
> The software I’m doing, prints some plots that I save as /.bmp/ and with
> /-mono/ and /-bestfit/ parameters. When I read them with “/imread/”
> function, I can see that it’s an indexed image and the matrix contains
> values [0 255].

What have you done so far? You can select a threshold, for example 127
and do
b = img > 127 to get a boolean matrix

I think you can increase the chance to get good answers if you upload
two images which you want to caompare and show the code you've written
so far to do the comparison.

-- Andy


Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

Octave - General mailing list
In reply to this post by marcasser
On 7/7/20 6:37 AM, Maria Jose Casas Serrano wrote:
The software I’m doing, prints some plots that I save as .bmp and with -mono and -bestfit parameters. When I read them with “imread” function, I can see that it’s an indexed image and the matrix contains values [0 255]. I would like to convert it to binary but without using the “image” package. 
(Yes, I know that this sounds weird but I would like to find a solution without using it, if possible. It’s due to some incompatibilities with some computers in the lab which cannot be updated to the last Octave version nor installing packages.)
Since you want  to namipulate images without using the image package, let me ask what is the goal. Do you want to simply see if they are different? Maybe you could just do system('md5sum image1 image2')? and if you want to see particular differences in images, why not store the plot data along with plot images, and compare the data?



Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

marcasser
In reply to this post by Andreas Weber-6
Hi Andreas,
Thanks for you tip. This helped me to re-orient my approach.

Maria


> On 7 Jul 2020, at 13:52, Andreas Weber <[hidden email]> wrote:
>
> Hi Maria,
>
> Am 07.07.20 um 12:37 schrieb Maria Jose Casas Serrano:
>> The software I’m doing, prints some plots that I save as /.bmp/ and with
>> /-mono/ and /-bestfit/ parameters. When I read them with “/imread/”
>> function, I can see that it’s an indexed image and the matrix contains
>> values [0 255].
>
> What have you done so far? You can select a threshold, for example 127
> and do
> b = img > 127 to get a boolean matrix
>
> I think you can increase the chance to get good answers if you upload
> two images which you want to caompare and show the code you've written
> so far to do the comparison.
>
> -- Andy
>
>



Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

marcasser
In reply to this post by Octave - General mailing list
Hi Przemek,

My goal is to compare the images to see their similarities. I’m modelling an evolutionary process and the fitness function needs to receive the binary matrix of the images, then it calculates the coincidence of their values (1 for background and 0 for foreground). Perhaps it sounds like I'm “re-inventing the wheel"… but I found some way to do it without losing much time. 

Thanks for your tip and your time. 

Regards,

Maria 

On 7 Jul 2020, at 22:43, Przemek Klosowski via Help-octave <[hidden email]> wrote:

On 7/7/20 6:37 AM, Maria Jose Casas Serrano wrote:
The software I’m doing, prints some plots that I save as .bmp and with -mono and -bestfit parameters. When I read them with “imread” function, I can see that it’s an indexed image and the matrix contains values [0 255]. I would like to convert it to binary but without using the “image” package. 
(Yes, I know that this sounds weird but I would like to find a solution without using it, if possible. It’s due to some incompatibilities with some computers in the lab which cannot be updated to the last Octave version nor installing packages.)
Since you want  to namipulate images without using the image package, let me ask what is the goal. Do you want to simply see if they are different? Maybe you could just do system('md5sum image1 image2')? and if you want to see particular differences in images, why not store the plot data along with plot images, and compare the data?





Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

Nicklas Karlsson
> Hi Przemek,
>
> My goal is to compare the images to see their similarities. I’m modelling an evolutionary process and the fitness function needs to receive the binary matrix of the images, then it calculates the coincidence of their values (1 for background and 0 for foreground). Perhaps it sounds like I'm “re-inventing the wheel"… but I found some way to do it without losing much time.
>
> Thanks for your tip and your time.
>
> Regards,
>
> Maria

You use saveas(...) function to save picture and imread(...) function to read the image into a matrix or similar.

You create figure with:
  h = figure;
So that you have a handle for the saveas(...) function. Also remember to chose format and add filename ending into filename. Suitable format is png for lossless compression or jpg which lose some information, typically high frequency sharp edges in case file size is important. To read file into matrix, may return several parameters:
  saveas(h, ...)
  [...] = imread(filename)

If in doubt about syntax:
  help saveas
  help imread

Then you have data for in the returned parameters you compare for their similarities but what kind of measure you have for similarities I have no idea.


Remember reading about evolutionary algorithms at spring time then it was nice weather, sitting inside programming generations of evolutionary algorithms.

Regards Nicklas Karlsson


Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

marcasser
HI Nicklas, 

I use print instead of saveas when saving the plot but as far as I know they are very similar, aren’t they?: 
# save as png monochrome
print(plothandler, filenameimage, "-mono);

And when reading the image I’m using imread but the image has grayscale color type and I should convert it to binary for the fitness function. Finally I got it but at the moment I sent the first email I was a bit stuck on this.

Thanks for you tip too ;)

Regards

Maria 


On 10 Jul 2020, at 13:41, N <[hidden email]> wrote:

Hi Przemek,

My goal is to compare the images to see their similarities. I’m modelling an evolutionary process and the fitness function needs to receive the binary matrix of the images, then it calculates the coincidence of their values (1 for background and 0 for foreground). Perhaps it sounds like I'm “re-inventing the wheel"… but I found some way to do it without losing much time.

Thanks for your tip and your time.

Regards,

Maria

You use saveas(...) function to save picture and imread(...) function to read the image into a matrix or similar.

You create figure with:
 h = figure;
So that you have a handle for the saveas(...) function. Also remember to chose format and add filename ending into filename. Suitable format is png for lossless compression or jpg which lose some information, typically high frequency sharp edges in case file size is important. To read file into matrix, may return several parameters:
 saveas(h, ...)
 [...] = imread(filename)

If in doubt about syntax:
 help saveas
 help imread

Then you have data for in the returned parameters you compare for their similarities but what kind of measure you have for similarities I have no idea.


Remember reading about evolutionary algorithms at spring time then it was nice weather, sitting inside programming generations of evolutionary algorithms.

Regards Nicklas Karlsson



Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

Nicklas Karlsson
> HI Nicklas,
>
> I use print instead of saveas when saving the plot but as far as I know they are very similar, aren’t they?:
> # save as png monochrome
>         print(plothandler, filenameimage, "-mono”);

Yes at least for these cases they produce the same result I can't imagine it can make a difference.

> And when reading the image I’m using imread but the image has grayscale color type and I should convert it to binary for the fitness function. Finally I got it but at the moment I sent the first email I was a bit stuck on this.

Grayscale is like 253 shades of gray plus black and white. Binary is zero or one. You may compare grayscale matrix against a number to get a binary result, black and white picture.


Reply | Threaded
Open this post in threaded view
|

Re: Binary image from a plot

marcasser


> On 10 Jul 2020, at 14:16, N <[hidden email]> wrote:
>
>> HI Nicklas,
>>
>> I use print instead of saveas when saving the plot but as far as I know they are very similar, aren’t they?:
>> # save as png monochrome
>>        print(plothandler, filenameimage, "-mono”);
>
> Yes at least for these cases they produce the same result I can't imagine it can make a difference.
>
>> And when reading the image I’m using imread but the image has grayscale color type and I should convert it to binary for the fitness function. Finally I got it but at the moment I sent the first email I was a bit stuck on this.
>
> Grayscale is like 253 shades of gray plus black and white. Binary is zero or one. You may compare grayscale matrix against a number to get a binary result, black and white picture.


Yeah, that exactly was what I did finally. I used a threshold to convert to white or black.

Thanks!!

Maria