quantitative analysis of bicyclus anynana‘s eyespot...

103
Universidade de Lisboa Faculdade de Ciências Departamento de Biologia Animal QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT WING PATTERN IMAGES Pedro dos Santos Lopes Mestrado em Bioinformática e Biologia Computacional, 2011 Bioinformática

Upload: others

Post on 03-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Universidade de Lisboa 

Faculdade de Ciências 

Departamento de Biologia Animal 

 

 

 

QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT WING PATTERN IMAGES 

 

 

 

Pedro dos Santos Lopes 

Mestrado em Bioinformática e Biologia Computacional, 2011 

Bioinformática 

 

 

   

  

Page 2: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

   

  

Page 3: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Universidade de Lisboa 

Faculdade de Ciências 

Departamento de Biologia Animal 

 

 

 

QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT WING PATTERN IMAGES 

 

 

 

Pedro dos Santos Lopes 

Mestrado em Bioinformática e Biologia Computacional, 2011 Bioinformática 

Master dissertation supervised by 

Dra. Filipa Alves, Instituto Gulbenkian de Ciência 

Dr. Gabriel G Martins, Faculdade de Ciências da Universidade de Lisboa

  

Page 4: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

  

Index 

Abstract ................................................................................... i Resumo ................................................................................. iii Introduction ........................................................................... 1 Objectives............................................................................... 3 Implementation ..................................................................... 4 

Input dialog ................................................................................. 5 Separation of each eyespot (wing) ............................................ 10 Analysis of the eyespot ............................................................. 14 

Analysis of normal images ............................................................ 14 Analysis of fluorescent microscopy images .................................. 23 

Auxiliary methods ..................................................................... 26 Results .................................................................................. 27 Discussion ............................................................................. 39 

Initial approach ......................................................................... 40 Current approach ...................................................................... 42 Future developments ................................................................ 46 

References ............................................................................ 47 Annexes ................................................................................ 49 

Variables .................................................................................... 49     

Page 5: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 

  

Page 6: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Abstract The main objective of this work is to provide researchers with a tool to quantitatively 

analyse images of the eyespot patterns present in the wings of the butterfly species Bicyclus anynana. More  specifically,  this  tool  is  a  plugin  for  imageJ,  a  free  open‐sourced  image processing program. 

Until now,  researchers have been using  software  such as  imageJ  to quantify  some dimensions of these patterns through manual measurements. This plugin offers an effective, quick and automatic way  to obtain  these measurements and others more difficult  to get until now, such as the area of each coloured region.  It also offers the possibility to obtain representative images of the eyespot(s). Besides images with a single eyespot, the program also analyses wing images with several eyespots as well as fluorescence microscopy images with  specific  proteins  labelled.  In  the  first  two  types,  the  program  finds  the  eyespots automatically  and  analyses  them  individually,  and  in  the  latter  ones,  the  program  can provide us with intensity plots of transversal cuts through the middle of the eyespot. 

To obtain the required data, the plugin  finds the centre of each eyespot and,  from there, searches for the frontiers of each of  its coloured areas. It then calculates their area, diameter and roundness which will be used to calculate the rest of the needed data and to create the representative  images.  In case of fluorescence microscopy  images, the program unites its coloured dots through a dilation process and then acquires the intensity plots. 

In  the  end, we  have  a  program  that  gives more  and  better  data  to  help  future research on evolution and development using this species and that could subsequently be transformed  into a more generic plugin capable of analysing any pattern containing closed frontiers due to  its strong aptitude to obtain these, regardless of any possible background noise. 

 

Keywords: Bicyclus anynana, ImageJ, eyespots, quantitative analysis, fluorescence microscopy. 

i  

Page 7: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Acknowledgements 

Dra. Filipa Alves, Instituto Gulbenkian de Ciência 

Dr. Gabriel Martins, Faculdade de Ciências da Universidade de Lisboa 

   

ii  

Page 8: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 

Resumo Este trabalho tem como objectivo proporcionar aos  investigadores uma ferramenta 

para  análise quantitativa de padrões  eyespot em  imagens de  asas de borboletas Bicyclus anynana,  nomeadamente  um  plugin  para  o  imageJ,  um  programa  de  análise  de  imagem gratuito open source. 

Até então tem‐se recorrido ao uso de softwares como o imageJ para obter algumas dimensões destes padrões através de medidores manuais de distâncias que se encontram disponíveis nos ditos softwares. Este plugin oferece um modo rápido e eficaz de obter essas medições de distâncias e outras que até então não eram possíveis de  serem obtidas por métodos manuais, como a área de cada região do eyespot e a circularidade (roundness) do mesmo.  O  plugin  também  oferece  a  possibilidade  da  criação  automática  de  imagens representativas do eyespot em análise, quer usando as  fronteiras  reais de cada área quer usando  representações  elípticas  das  mesmas.  Para  além  de  imagens  com  um  eyespot individual,  o  programa  também  analisa  imagens  de  asas  com  vários  eyespots  bem  como imagens de microscopia de  fluorescência mostrando expressão da proteina Distal‐less ou Engrailed. Para os primeiros  tipos de  imagem, o programa encontra automaticamente os eyespots e analisa‐os individualmente, e para os últimos o programa possibilita o retorno de cortes  transversais,  passando  pelo meio  do  eyespot,  através  de  gráficos  de  intensidades, que auxiliam o investigador na sua análise. 

A espécie Bicyclus anynana tem eyespots anterior e posterior nas superficies ventral e dorsal das asas dianteiras e vários eyespots na superficie dorsal das asas traseiras. Estes padrões  são  circulares  e  são  de  diferentes  tamanhos  e  têm  a mesma  constituição:  uma pequena  área  branca  no  centro  com  aproximadamente  um  centésimo  do  tamanho  do eyespot, uma área preta predominante e uma faixa amarela em torno desta, envolvendo o eyespot.  Estes  aspectos  morfológicos  têm  uma  grande  variação  genética  e  todos  eles mostraram  que  reagem  em  conjunto  à  selecção  artificial  e  até mesmo  a mutações.  Esta aparente  união  é  devido  a  partilharem  o mesmo  tipo  de  desenvolvimento,  a  partir  de centros organizadores denominados por foci, sendo também observado uma expressão de genes de desenvolvimento característica em préadultos. No entanto, um grande potencial para variação independente do tamanho do eyespot tem‐se observado. Para estudar mais a fundo  estas  variações  neste  tipo  de  padrão,  é  preciso  obter‐se  dados  de  aspecto mais quantitativo para se ter uma correspondência mais precisa e significativa entre a expressão genética e a variação fenotípica que se observa no indivíduo adulto. 

Para  a  obtenção  dos  dados  pretendidos,  o  plugin,  para  imagens  de  eyespots individuais ou imagens de uma asa, obtém o centro do(s) eyespot(s) e, a partir dele, procura as três fronteiras que o constituem. Ao encontrar cada fronteira, o programa regista essas fronteiras  individuais  e  utiliza‐as  para  obter  informações  como  as  áreas,  diâmetros  e circularidade que depois servem para os cálculos pretendidos de proporções entre áreas ou 

iii  

Page 9: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

criação das imagens representativas. Para a obtenção destas fronteiras, o programa binariza a imagem, onde depois é aplicada a função outline e skeletonize, obtendo‐se assim linhas de um  pixel  de  largura.  Depois  o  programa  segue  por  cada  uma  delas  num  determinado sentido e percorre‐as somente pelo caminho mais curto, sem se enganar por possíveis erros presentes na  imagem. Para saber qual o caminho a seguir, o programa pinta cada  lado de cada  linha  com  uma  determinada  cor  e,  para  ser  a  linha  correcta,  esta  tem  de  ter  pelo menos  um  pixel  de  cada  uma  destas  cores  presente  na  sua  vizinhança.  Existem  casos especiais que podem ocorrer, como haver mais que um pixel para seguir que contenha as condições certas ou o lado exterior não ter sido completamente pintado para poder seguir em  frente, por exemplo. Para estes  casos e outros, existem outro  tipo de  subregras que depois são aplicadas, de modo a possibilitar ao programa seguir em frente e continuar pelo caminho  certo.  São  estas  correcções  e  subregras  que  fazem  com  que  o  plugin  seja relativamente robusto em relação a possíveis indefinições existentes na própria imagem. No caso de imagens de uma asa, para se obter dados correctos e individuais para cada eyespot, o programa tem de os separar, e fá‐lo traçando rectas entre eles, de modo a que quando o programa obtém a última fronteira, a exterior, o programa não siga para o eyespot vizinho e o contabilize para os dados do eyespot a ser analisado. Ao finalizar a análise de cada um dos eyespots, o programa  volta a pintar o que  coloriu  com as  cores originais, branco para as áreas e preto para  as  fronteiras, de modo  a não ocorrer erros  com  a  análise do  eyespot anterior. 

No  caso  de  imagens  de microscopia  de  fluorescência,  sendo  esta  constituída  por pontos  coloridos  num  fundo  preto  que  correspondem  à  expressão  de  uma  determinada proteína,  o  programa  une  esses  pontos  através  de  um  processo  de  dilatação  para  dar volume ao eyespot e proceder então aos cortes transversais pretendidos pelo utilizador. Um dos  tipos de  cortes possíveis é um  corte médio que  corresponde a uma média de  vários cortes ao  longo do eyespot em diferentes ângulos. Para tal, o programa cria uma  imagem que  é  a média  entre  várias  imagens,  cada uma delas  com uma determinada  rotação  em relação à anterior com centro no meio da região central do eyespot. O programa também possibilita  a  obtenção  de  outros  dados  como  a  área,  o  diâmetro  e  a  circularidade (roundness) para cada região. 

Como  resultado  final,  tem‐se  um  programa  que  analisa  quantitativamente  os padrões  eyespot  presente  nas  asas  de  borboleta  da  espécie  Bicyclus  anynana,  que  nos possibilita  ter  uma  coneccção  mais  fidedigna  entre  o  padrão  observado  e  a  expressão genética envolvente na sua formação, obtendo‐se assim mais e melhores dados de análise para  futuros  trabalhos  de  investigação  em  evolução  e  desenvolvimento  usando  esta espécie. Posteriormente, este plugin pode ser  transformado num mais genérico, capaz de analisar qualquer padrão constituido por  fronteiras circulares  fechadas, devido à sua  forte capacidade de obtenção deste tipo de fronteiras apesar de qualquer possível ruido de fundo na imagem. 

 

iv  

Page 10: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Palavras chave: 

Bicyclus  anynana,  imageJ,  eyespots,  análise  quantitativa,  microscopia  de fluorescência. 

v  

Page 11: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

vi  

   

Page 12: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Introduction  The colour patterns on butterfly wings are a great example of phenotypic variation. 

These patterns can vary both across and within species and are ecologically significant, often having a known adaptive value. The butterfly Byciclus anynana became an important model to study adaptive morphological evolution in evolutionary developmental biology due to its variable wing color patterns, namely the eyespots, and because it can be easily maintained in  the  laboratory. Evolutionary  and developmental biology  is  confronted with  the  task of understanding  the  genetic  bases  of  phenotypic  variation.  For  this  reason,  the  genetic pathways involved in eyespot formation and the physiological basis of its plasticity as well as the biochemical pathways of the pigments formation have been the object of study (3). 

Knowledge  from  Drosophila  melanogaster  wing  development  studies  have contributed to the understanding of butterfly wing pattern formation, having a number of its developmental pathways been implicated in butterflies, like the Distal‐less (Dll), engrailed (en), spalt  (sal) and Notch  (N) genes  that are expressed  in the eyespot area  in developing wings. Although useful,  this  approach only  gives us  candidate  genes  from  the Drosophila and not all the ones involved in butterfly wing formation (1). Since Diptera and Lepidoptera are quite different, namely,  for  the  case  in  study,  their wings, we  can  conclude  that  it  is likely that not all the involved genes will be the same as in Drosophila, and a more profound search is necessary to fully understand the butterfly wing colour evolution and development (3). 

Bicyclus anynana has  an  anterior  and  a posterior eyespot on both  the dorsal  and ventral  forewing  surfaces  and  several  eyespots  on  the  dorsal  hindwing  surfaces.  Each eyespot  is approximatelly circular  in shape and may have a different size, but all have the same colour composition: a small white centre area roughly 1/100th of the eyespot, a large middle  black  area  and  a  narrow  yellow  ring  surrounding  it.  These morphological  aspects have  a  great  phenotypic  variation,  but  all  of  the  eyespots  have  been  shown  to  react  to artificial  selection  in  unison  and  can  also  be  affected  as  a  group  in  some wing  pattern mutants. This association between  the eyespots  is due  to  the  fact  that  they all  share  the same developmental basis while  they are  formed  from  central organizers  called  foci. The characteristic eyespot shape can already be recognized in the wing disk of the late pupa by the expression pattern of some developmental genes (e.g. en, sal Dll). Consequently, we can view  the  whole  pattern  of  eyespots  as  a  single  module  that  is  evolutionary  and developmentally  independent from those of other pattern elements present on the wings. Some  aspects  of  eyespot morphology  have  genetic  correspondences  between  eyespots, being  stronger  for  eyespots  on  the  same  wing  surface.  It  has  been  shown  that  these correspondences determine the eyespot size and the whole pattern,  including  in different wing surfaces and, to some degree, other features of eyespot morphology. However, great potential has been  found  for  independent variation of eyespot size even  though  there’s a strong genetic connection between eyespots on  the  same wing  surface. This goes against 

1  

Page 13: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

the  prevalent  role  of  developmental  constraints  derived  from  the  coupling  between individual  eyespots  in  shaping  the  evolution  in  eyespot  size.  This  seemingly  overridden aspect suggests that the genetic correlations aren’t a major factor constraining wing pattern formation. Even though there’s obvious genetic connections, it is known that eyespots from dorsal and ventral  surfaces are  rather  independent, as,  for example,  the ventral eyespots show plasticity  in  their  size depending on  temperature and hormonal  regulation whereas dorsal eyespots do not (2). 

Some  genetic  tools  are  currently  being  developed  for  B.  anynana  like  the construction of a Bacterial Artificial Chromosome  library  (3), and an extensive Expression Sequence  Tags  project  is  being  done,  that will  help  identify  new  genes  involved  in wing pattern  formation  and  variation  as well  as  to  serve  as  a  basis  for  the  development  of  a linkage map  and DNA microarrays  and  to  help  identify DNA  sequence  polymorphisms  in wing genes using its redundancy. These polymorphisms could be then used to build a high‐density gene‐based linkage map for this species that will be an essential help to the mapping of the wing pattern variation to gene regions, and at the same time testing the contribution of  a  number  of  candidate  loci  to  this  variation  (1).  The  development  of  germline transformation  techniques  for  this  butterfly  is  also  a  recent  development  in  its  studies, being the only butterfly species to date where this is possible. All these techniques and tools in development are going to be crucial in testing the function of candidate genes and their contribution to pattern development and evolution, as well as in providing the first steps of the development of more sophisticated gene manipulation techniques already available  in other model systems (3). 

Furthermore, a modelling approach of the pathways involved in the eyespot pattern formation  is  currently  underway  in  order  to  help  understanding  the  regulatory  relations among the candidate genes, and also to predict other unknown genes possibly  involved  in this development process. To help this approach, new ways of measuring the eyespots and their  phenotypic  variation  are  needed  in  order  to  quantify  the  natural  variation  in  the patterns,  as  well  as  the  possible  experimentally  induced  alterations,  either  by  artificial selection (selective breeding) or by mutations. To this day, these measurements were made coarsely and prone to human errors as they were being made “by hand”. In order to obtain more precise values, and others that until now weren’t possible to obtain, a new automatic measurement  tool must be created and  that’s  the main goal of  this work. By providing a precise  quantification  of  the  eyespot  images,  this  tool  enables  the  objective  comparison between  the  different  variants  of  the  same  pattern,  both  in  wild  type  and  mutant butterflies, thus contributing to stablish a more meaningful correspondence between gene expression and phenotypic variation. 

   

2  

Page 14: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Objectives The main goal of this work  is to provide the researchers working with the butterfly 

species  Bicyclus  anynana  with  a  tool  to  quantitatively  analyse  images  of  the  eyespots present  on  their  wings.  Because  the  study  of  their  formation  cannot  be  done  without studying  gene  expression,  this  tool  also  analyses  fluorescence microscopy  images  of  the eyespots where the expression pattern of some genes is analysed. 

This project uses  ImageJ as the platform  for the tool created,  in this case a plugin. Because  it’s a public domain,  java‐based  image processing program and  its source code  is freely available, it proved to be a good choice to provide the researchers an inexpensive tool for their works (15). 

This plugin analyses several different types of  images:  images with a single cut‐out eyespot on  them,  images of  the whole wing, both  fore and hind wings, and  fluorescence microscopy  images  with  a  single  eyespot,  showing  the  homologues  of  Drosophila melanogaster gene product expression for  Engrailed. 

Previously,  the  methods  used  to  compare  eyespots  were  rudimentary,  such  as measuring their diameters with a program ruler, from edge to edge. These types of methods are more laborious and less producible or thorough so a more precise tool is required, one that  would  automatically  identify  spots  and  calculate  data  such  as  areas,  roundness, diameters, intensities, without the normal human errors and biases that come with manual measurements. This plugin will allow  future works on  this  subject  to have more accurate quantitative data rather than manual measurements and comparison of different eyespots, as well as a faster and quicker method/tool to analyse the images collected experimentally. 

 

 

   

3  

Page 15: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Implementation 

The plugin is composed of four parts as shown in the diagram below. First we have a section  that  contains  the  code  for  creating  the  initial  input  dialog  in which  the  user  can choose  the wanted output parameters,  then we have  the main body of  the program  that contains a section to separate each eyespot in case the user analyses the whole wing and a section that performs the analysis of the eyespot. This is the main section which is used to analyse all image types and is divided into two distinct subsections: the first analyses normal images and the other performs the analysis of fluorescence microscopy images. At the end of the code there are some auxiliary methods to be used on the main body. 

The images used to test and obtain the data to perform comparisons between them comes from the articles referenced at the end after the discussion section. 

 

 Figure 1: main structure of the program. 

   

4  

Page 16: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Input dialog 

The input dialog section contains the code to create the initial menu for the user to choose the output parameters. This initial section actually consists of two separate dialogs: the  first one  asks  the user  to  select  the  type of  image  to be  analysed, which  is  going  to define  the  composition of  the next one,  and  the  second will  ask  the user  to  choose  the output parameters as well as other information, depending on the type of image selected. 

The first dialog is a very straight forward drop down choicer, as it can be observed on the  image  below.  The  user  is  allowed  to  choose  between  “Single  Eyespot”,  “Forewing”, “Hindwing”, “Distal‐less” and “Engrailed”. 

 Figure 2: first input dialog for choosing the type of image to analyse. 

The program then sets the default number of eyespots in the image, one for “Single Eyespot”,  “Distal‐less”  and  “Engrailed”  images,  two  for  “Forewing”  images  and  seven  for “Hindwing” images. 

The second dialog is different for each type of image to analyse. 

When the user chooses the “Single Eyespot” option, the program will recognize the image as being a normal  image (not a fluorescence microscopy one) with a single eyespot cut from a wing, and will analyse it using only the subsection ‘analysis of normal images’. 

Its second dialog (fig. 3) has two parts: one in which the user selects which areas to study (the options are the eyespot  in  its totality and each  individual areas) and another  in which the user can introduce the scale of the image (pixels/mm), manually or selecting the image scale set on imageJ or present in its metadata, and select which output data to get. In the  later part,  the user  can  choose  to obtain  the area,  the  roundness and  the diameters (minimum and maximum)  for the selected areas to study.  It  is also possible to get several areas ratios by selecting which areas to use, as well as image representations of the eyespot using  the  real  frontiers  for  each  area  (Coloured  original  areas)  and  using  elliptical representations of each  frontier  to draw  the eyespot  (Coloured elliptical areas). The user can also choose to analyse all the opened  images (though they all have to be of the same image type) and to show binary images for each individual area (white, black and yellow). 

5  

Page 17: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 3: second input dialog for “Single Eyespot” image. 

If  the user chooses either  the “Forewing” or “Hindwing” options,  the program will recognize the image as being a normal image of a whole wing (at least with all the eyespots visible)  and will  analyse  it  using  the  ‘separation  of  each  eyespot  (wing)’  section  and  the same analysis used for the previous case. 

In this case, the second dialog (fig. 4) is the same as the previous one (fig. 3) with an additional part  in which the user has to  introduce the number of eyespots on the wing as well as which eyespots to analyse, using in this case the word ‘all’ for analyse all eyespots or introducing the number of the eyespots (ordered from top to bottom) separated by a dash (‐). The user can also choose  to view  the outlined binarized  image with  the dividing  lines (that mimics the division provided by the veins). 

6  

Page 18: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 4: second input dialog for “Forewing” and “Hindwing” image. 

The  last  two  options  will  tell  the  program  that  the  image  is  a  fluorescence microscopy one with a single eyespot and will analyse it using only the subsection ‘analysis of fluorescence microscopy images’. 

The second dialog (fig. 5)  is somewhat simpler than the previous ones since  it only has  the  part where  the  user  introduces  the  scale  (pixels/mm), manually  or  selecting  the image scale set on  imageJ or present  in  its metadata, and select which output data to get, such  as  the  area,  roundness  and  diameters  (minimum  and maximum)  for  all  areas.  It  is possible to obtain an image representation of the eyespot using elliptical representations of each  frontier  and  cross  sections  (average,  along  the minimum  diameter  and  along  the maximum diameter), perpendicular to the image. There is also the choice to analyse all the opened images. 

7  

Page 19: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 5: second dialog for the “Distal‐less” and “Engrailed” image. 

In order to proceed correctly to the analysis, the program searches the user input for errors and gives the corresponding alert. Some conditions must be observed: the characters for numbers in the dialog must be numbers; the number of eyespots present must be bigger than zero; the number of eyespots to be analysed must be smaller or equal to the number of eyespots present  in  the  image;  to  calculate areas  ratios  there must be more  than one area selected  in the ‘Area ratios’ section; the user must select at  least one area to analyse and select at least one output data. Also if any of the selected areas for the areas ratios isn’t included in the areas to study, the program asks the user if it should proceed. 

After  this  dialogs  and  if  the  user  has  chosen  a  “Single  Eyespot”,  “Forewing”  or “Hindwing” image type, the program continues by applying the macroWork method. 

The macroWork method, which is found at the end of the program, returns an image with the skeletonized outlines of the binarized  image. This process starts by extracting the Brightness portion of the original image, by splitting it into an HSB stack and retain only the Brightness  for analysis. As opposed to simply convert the  image  into an 8‐bit black/ white image,  the  Brightness  portion  provides  us with  a more  reliable  image  in  terms  of  pixel intensity  quantification  which  correlate  to  the  colour  intensity,  since  each  colour  have different brightness (as noted in the use of different coefficients in the formula Y = 0.299R + 0.587G  +  0.114B  to  calculate  the  value  for  each  pixel).  Therefore,  the  image  obtained  is composed of  the biggest value of  the  red, green and blue group, giving  the best contrast between each area and not  loosing  information  in  the process, as  shown  in  the example below. 

8  

Page 20: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 6: left – conversion to 8‐bit; right – Brightness image (from HSB stack). 

After  obtaining  this  image,  the  program  applies  a Gaussian  blur  filter with  sigma (radius) equal to one pixel to eliminate small irregularities, which could originate errors, and converts it to a binary image. Then the program outlines and skeletonizes it, getting this way the one‐pixel‐width frontiers separating the different zones (fig.7). Because each image has their own error prone irregularities, the program shows the user the result image and asks if the frontiers of interest are well defined. At that time, the user can apply more or decrease the blur sigma used before and the program will do the binary image again, using this new value. When the frontiers are acceptable, the program can continue the analysis. 

 Figure 7: image with the skeletonized outlines of the binarized original image. 

9  

Page 21: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Separation of each eyespot (wing) 

This  section  is  only  used  for  “Forewing”  and  “Hindwing”  images  and  consists  in separating the eyespots from each other  in case there’s merging of neighbouring eyespots through the yellow area. 

This part of the program obtains the coordinates for each eyespot centre and draws dividing  lines  between  each  eyespot  on  the  image with  the  skeletonized  outlines  of  the binarized original image (fig. 8 – right image). 

 Figure 8: left – original image (bigeye mutant); centre – eyespot representation image; 

right – skeletonized outlines of the binarized original image with dividing lines. 

Firstly the program has to check if the image contains a white background in order to eliminate  it.  This  is  required  because  the  program  searches  for  the white  areas  as  the position  reference  for each eyespot. As  the wing  is  round  shaped,  the most efficient and quick method  to accomplish  this  is by  inspecting each corner  for white pixels.  If  there’s a white  background,  the  image  is  binarized with  a  threshold  of  128  (middle  point  in  the gradient range of 256) and a great part of  its smallest holes filled with the close operator, which is a morphological operator which is simply a dilation followed by an erosion, and the dilate operator. In spite of this processes and even if the ‘fill holes’ function is used, the wing still  could have holes on  the edges of  the  image, mainly because  the  ‘fill holes’  function searches  the  sides  for  the background  colour  so  that  it  can  identify  the area outside  the object  that  is going  to have  its holes  filled. A work around  for  this possible problem  is  to make  the  program  draw  lines  around  the  edges where  the wing  touches,  by  finding  out where the white corners finish and the wing starts and drawing a line between them. After this, the ‘fill holes’ option is applied and all that is left is the white background and the black 

10  

Page 22: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

section of the wing. Then the  image  is  inverted and framed with a white  line around  it, to account for small white pixels at the border of the wing which could be just at the edge of the image, followed by some dilation, also to account for the same possible problem. After all this steps, this image is added to the original one, overlapping the white background (fig. 9 – right image). 

 Figure 9: left – original image; right – image without the white background. 

The next  step  consists  in  finding  each  eyespot present.  For  this,  the program will search for the white centre area pixels with the value given by the pixelLimit variable (equal to 255 to start with) for each colour. Once it’s found a pixel with that value, it is inserted in a blank  image. After  all  the pixels have been  analysed,  the program  investigates  the blank image with the particle analyser function to see if there’s at least as much particles as there is eyespots, number that was provided by the user earlier in the second initial dialog. If this is  false,  the program  then decreases  the pixelLimit  value by one  and  searches  the pixels again, creating a new blank image for it. This process continues until the previous condition is true, and then it shows the result blank image with the possible locations for each eyespot and  subsequently  asks  the  user  if  it  contains  all  of  the  eyespots  present  in  the  original image.  If  some  of  them  aren’t  in  the  correct position,  it means  that  it’s  a  false  eyespot, probably an error  from the photography, and  the program will have  to analyse  the  image again to find the missing eyespot(s). After  it has found all the eyespots,  if there were false ones,  the  program  asks  the  user  to  select  with  the  mouse  pointer  the  particles  that correspond to the real eyespots (this  is a user friendly  input because the selection doesn’t have  to be  so  accurate or  sequential)  and  it will make  a  correspondence between  those points selected and the nearest particle, followed by the sorting of the eyespots from top to bottom.  If the user selects a different number of points than the number of eyespots, the program will alert the user to the situation, allowing him to correct this. 

11  

Page 23: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

The final step of the separation of the eyespots consists in drawing the dividing lines between them. 

First the program starts to make an image with the outlines of the binarized original image  the  same way  the macroWork method do but without  the  skeletonize  function,  so that  the outlines are  continuous without diagonal breaks. To draw  the  line between  two eyespots, the program needs to know what its slope is and where it is going to pass, which will  be  a  point  between  the  black  area/  yellow  area  frontiers.  To  find  out  the  latter,  an imaginary  line  is drawn connecting  the centres of  the  two eyespots  to be analysed. Then, starting  from  each  eyespot  centre,  the  program will  run  along  the  line  until  it  finds  its frontier between the black and the yellow areas. The running process actually starts at 1/8th of  the distance between  the eyespots and  if  it  found only one of  the  frontiers due  to  its absence or to poor quality of the image or even possibly the merging of the black areas, the program sets the passing point as the middle of the imaginary line. The other passing points, for  “Hindwing”  images,  are  set more  or  less  near  the  frontiers,  depending  on  the  ratio between them, with some exceptions. This deviation from the centre of the zone between each black area/ yellow area frontier is necessary because by observing the images, we can perceive  that  the  veins  are  closer  to  the  frontier  belonging  to  the  biggest  of  the  pair  of eyespots. So by applying this ratio to the calculation of the passing point, the separation of the  eyespots  gets more  accurate  by mimicking  the  position  of  their  natural  dividers,  the veins,  and  thus  getting  a more  precise  area  value  for  each  individual  yellow  area.  For “Hindwing”  images  from mutated  individuals with  extra  eyespots  the  value  used  for  the ratio  is 0.5, mainly because by having extra eyespots,  their positions may cause problems with their normal arrangement and could cause the divisions to occur in odd places. In the case of a hind wing with seven  (or even eight eyespots – although a mutant, this eyespot position don’t disrupt  the normal  layout of  the  rest)  the  ratios are  treated differently  for each  case.  For  the  first  four  eyespots,  the  ratio  used  to  determine  the  position  of  the passing point  is the calculated one and  for the rest of the eyespots the ratio  is 0.5 due to better division with this value than with the calculated one. The ratio of 0.5 is also used for all the other cases. 

After  finding out  the passing points  for  the  lines,  the program  is going  to calculate their slopes which is very straight forward since they’re perpendicular to the imaginary lines between the eyespots’ centres. Although logic dictates that for each pair of eyespots, these imaginary lines are suppose to be between the eyespots in question, we observe that most of the times, for hind wings, this doesn’t reflect the positions of the veins at all. So we found out  that  by  using  other  eyespot  to  pair with  the  upper  one  of  the  pair, we  get  a more accurate  line.  Even  though  the  veins  are  slightly  curved,  the  lines  almost  exactly overlap their terminal portions where the eyespots are (see fig. 8). So when the program analyses “Hindwing”  images and  there’s seven or even eight eyespots present,  the pairing are:  the first with  the  fifth,  the  second with  the  fifth,  the  third with  the  sixth,  the  forth with  the seventh,  the  sixth with  the  seventh,  the  seventh with  the  sixth again and,  for  the eighth 

12  

Page 24: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

eyespot, the seventh with the eighth. For the other cases, the slope  is calculated using the eyespots that bracket them. 

In  the  end, with  the  values  for  the  slope  and  the  passing  position,  the  program calculates  the  equations  for  the  dividing  lines  and  draws  them  over  the  skeletonized outlines of the binarized original image, which can be viewed if the user chooses to. 

 

   

13  

Page 25: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Analysis of the eyespot 

Analysis of normal images 

This subsection is used when the “Single Eyespot”, “Forewing” or “Hindwing” option is selected during the first initial dialog. It’s the one that gives the user the outlines of each area and their data (area, roundness, diameter, area ratios and  image representations) for normal eyespot or wing images. 

To obtain the frontiers of each eyespot, the program starts at  its centre and moves along the pixel line to the right until it has found three frontiers (this method is performed for each eyespot in the case of a wing image). So first the program sets the eyespot centre coordinate. If it’s a wing image, the coordinate is set as the current eyespot to be analysed, found  by  the  ‘separation  of  each  eyespot  (wing)’  section,  and  if  it’s  a  “Single  Eyespot” image, the coordinate is set as the centre of the image. Also in this latter case, the image is framed with a black line encased in an exterior colour line (more about colours later – also see  fig.  11  for  colour  codes),  to  account  for  single  eyespots  that  could  be merged with another out‐of‐frame eyespot or  for  those  that  could be missing parts of  its yellow area. Mainly because  the “Single Eyespot”  image could possibly not be centred properly on  the image frame or to account for the possibility of some error with the outlines, the program now applies the findWhite method to this centre point, in order to find the closest white (or close to white) pixel. 

The  findWhite method, which  is  found at  the end of  the program,  returns a set of coordinates  (x, y)  from  the original  image, corresponding  to  the closest white  (or close  to white) pixel to the given set of coordinates. The value used to find this pixel is the pixelLimit variable discussed above. When the image type is “Single Eyespot”, the default value is set to 245  and not 255  to  take  into  consideration  the possibility of  image quality error. This method  works  by  comparing  the  pixels  in  a  spiral  motion  (fig.  10)  around  the  initial coordinate until one with all  the  three RGB values equal  to  the pixelLimit value or,  in  the case of a “Single Eyespot”  image, until  it reaches  the  limit of  the  frame. For wing  images, this method doesn’t need to rely on this  latter condition because  it most certainly  finds a pixel right at the  initial coordinate. If either of the returned coordinates are zero,  it means that  it didn’t find the pixel, and so the program sharpens the  image and tries again until  it has  found  out  a  correct  set  of  coordinates  to  start  the  search  for  the  three  frontiers properly. 

14  

Page 26: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 

Figure  10:  code  snippet  from  the  findWhite  method  that changes  the  coordinates  in  order  to  run  a  spiral path  around  the  initial  pixel.  The  side  variable gives  the  length of  the path  to  run until  it  turns, the i variable keeps the pace for each run and the a variable serves as an alternate switch between 1 and  ‐1,  in order  to  change  the direction  for each half turn. 

After the program has found the initial pixel, it paints the white area with its colour (more about colours later – also see fig. 11 for colour codes) and it starts the search for the frontiers  of  each  area.  To  do  this,  the  program  runs  along  the  x‐axis,  starting  from  the previously  obtained  set  of  coordinates,  until  it  finds  a  black  pixel. When  this  occur,  the program  analyses  the  next  pixel  colour.  If  it’s white,  then  it most  certainly  is  a  possible frontier. If it’s another colour besides white or black, it’s most likely some black pixel or line that doesn’t make part of a frontier – the area outside the frontier is supposed to be a non‐painted white area, so  the program continues  the search  forward  for another black pixel. After it has found a possible frontier, with a white area on the other side, the program runs along the frontier and registers each of its pixels onto a separate blank image corresponding to  that area of  the eyespot. This  just cannot be done by  simply  find  the next black pixel, going up or down, because there could be several black pixels or  lines that go through the frontier and mislead the program and causing it to go the wrong way. The best way to avoid this is to simply give the program a sense of where it is along the line. The line that makes the  frontier must be  surrounded by a different area on each  side.  So  to distinguish both sides, the program paints the next area with a different colour and simply follow some rules. The colours used are shown bellow. 

 Figure 11: colour scheme used to run through the frontiers. 

The first four colours are used for each or the areas: white area, black area,  yellow  area  and  exterior  area.  The  other  three  colours  are respectively: debris colour, line colour and initial pixel colour. 

15  

Page 27: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

As it can be seen, there’s one colour for each area around each frontier and there’s also three extra colours used for the frontier itself: the first to paint black pixels that aren’t the next pixel of the frontier, the second to paint the correct frontier pixels themselves and the third to paint only the first found pixel of the frontier. The frontier  is completed when the program  finds a pixel with  the  initial pixel colour and  it paints  this pixel with  the  line colour and floodfills  it with the debris colour, so that  in the end the program can paint all the line back to black to account for the merged eyespots possibly present in wing images, which have the same external frontier in the dividing lines area. 

To get the program to follow a specific direction, the next thing it does is to apply the debris colour to the black pixels present bellow the first frontier pixel. This way the program can only go up, and this pixels will be coloured back to black afterwards so that they too can be analysed. After this, the program now analyses the neighbours of the current pixel to find which  black  pixel  is  the  next  one.  This  analysis  is  done  by  analysing  the  neighbours’ neighbours,  giving  weights  to  each  black  pixel  neighbour  in  accordance  with  its  area coloured neighbours and setting different viability values for each type of situation (example in  fig. 12). The program detects  if  the black pixel neighbours have at  least one neighbour with the inner area colour and at least one with the outer area colour and how much inner coloured and line coloured neighbours it has. 

The value given to each neighbour is one of the following: 

1  –  if  it’s a (viable) black pixel with at  least one  inner area coloured neighbour and one outer area coloured neighbour; 

2  –  If it’s a (non viable) black pixel that doesn’t comply with the previous rule; 

‐1  –  if it’s the pixel with the initial pixel colour;

‐2  –  if it’s a white pixel; 

0  –  if it’s a pixel with some other colour (area, debris or line colour).

 

Figure 12: example of current pixel neighbourhood analysis. In this case we can see that there are three black pixels. After the neighbourhood analysis,  it can be observed  that  there’s only  one  pixel  that  qualifies  to  be  the  next  frontier  pixel, marked  with  1.  The  other  two  don’t  have  all  the requirements  as  they  don’t  have  at  least  one  inner  area coloured  neighbour.  Note  that  there’s  no  way  for  the program  to  run  backwards  as  the  previous  frontier  pixel  is line coloured.  

 

16  

Page 28: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

The number of inner coloured neighbours and of line coloured neighbours, as well as the  viability  value,  are  set  to  zero  for  the  central pixel,  in order  to eliminate  it  from  the neighbours. 

Following the frontier line isn’t as easy as finding the next single black pixel. Several types of error could occur due to possible lines derived from the background noise or even from excess of resolution. This  lines could cross or even go side by side along the  frontier and some holes could appear at  its side or even right  in the pixel  line the program uses to find the frontiers. The figure 13 illustrates most of those errors, if not all, that could possibly occur. 

In the  first  image  from  figure 13, there are three situations that could happen and destabilize  the  analysis.  The  topmost one  reveals  that  it  could occur  that  there  could be some  lines that go from the current frontier to the next, blocking the 4‐connected floodfill method  to paint all of  the exterior area. When  the program  reaches  this point,  it doesn’t find any viable black neighbour pixel since the topmost one doesn’t have any outer coloured neighbour pixel and the lower right one doesn’t have any inner coloured neighbour pixel as well.  So,  in  this  possible  scenario,  the  program  searches  for white  neighbour  pixels  and floodfills  them with  the outer  colour,  revert any debris coloured neighbour pixel  to black and analyses the pixel again for viable black neighbour pixels. The next situation is the one where  the program encounters  two viable black pixels next  to each other.  In  this case,  it simply chooses the one  in the corner and dismisses the other as debris. The  last one, and also  the next  three  images,  is about  the  first encounter of a possible  frontier.  In  the  first image we have the case where there’s a  line coming  from the  frontier  inwards. Obviously the pixel the program found  isn’t the one of the frontier. So  it moves forward  in search of viable  black  neighbour  pixels  that would  symbolize  the  presence  of  the  frontier.  In  this particular case, when it reaches the X point, it chooses the viable black pixel in the corner, as discussed above. The next  image shows that  it could have a closed  loop  in the path of the pixel line used to search for the frontiers. When this occurs, the program bypasses it simply by verifying if it’s running along the line in a clockwise motion. In the two following images, it’s  represented  the  case where  there’s  two or  even  three  viable black neighbour pixels, respectively. In both cases, the program chooses the top leftmost viable black pixel. 

In the lower three images from figure 13, there’s other three possible problems that could occur. The first image shows that there could be a closed loop adjacent to the frontier. In this case, the program simply treats this as a case of absence of viable black neighbour pixels, equal to the situation previously mentioned, and  floodfills  it with outer colour. The second  image  illustrates the situation where there’s a  lack of viable black neighbour pixels and  there’s white pixels  to  floodfill. But  in  this particular  case,  there  could be a previous situation of two viable black neighbour pixels in which the program colorized the other left out viable pixel with the debris colour. When  it goes to return this pixels back to black to analyse again, the program in the next analysis of the same pixel will have two viable black 

17  

Page 29: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

neighbour pixels but not touching each other. In this situation, the program chooses the one with the least number of line coloured neighbours which is the one in the right. And finally in the third image there’s the situation where the frontier has a line next to it, side by side, and there’s no viable black neighbour pixels nor even white neighbour pixels to floodfill. So the program chooses  the black pixel with  the  least number of  inner coloured neighbours, allowing  it to proceed along the  line until  it finds a white pixel to floodfill or a viable black pixel to continue on. 

 Figure 13: possible situations in which the program could fail to perform correctly. 

Each  picture  represents  a  portion  of  the  frontier  line  in  a  given  situation.  The  already travelled is painted with the line colour – the darkest gray – and the non viable black pixels are painted with the debris colour – a slightest clear tone than the  line colour but darker than the area colours. The  initial pixels are marked with an X and the possible situation  is marked by a black arrow. The direction of the analysis is given by the red arrows. 

Bearing  in mind  these possible situations  that could complicate  the analysis of  the lines,  the program has  to  select  the next  frontier pixel  to be  analysed. There  are  several possibilities  that could occur and  they’re  set  in Boolean  statements  (see  flow chart  in  fig. 15). The first possibility is the presence of the initial coloured pixel, and if the current pixel’s not one of the first three to be drawn in the blank temporary images of the correspondent area, which  the  program  selects  as  the  next  and  final  pixel  of  the  frontier.  Then  if  the program doesn’t  find any viable black pixel and  it’s not  the  first pixel  to be drawn,  it will floodfill  all  the white  neighbour  pixels with  the  outer  colour  and  converts  every  debris coloured neighbour pixels back to black, returning to analyse the current pixel again. It could occur  the possibility of nonexistence of white pixels mainly because  there could be a  line along that part of the frontier or some extra pixel making a block like point. If it’s the case, the program  then  sets  the next pixel as  the one with  the  least number of  inner coloured neighbour pixels. The next possible case is the one where there’s only one viable black pixel which is selected as the next one of the frontier. Subsequently we have the cases of several viable black pixels. The case  in which there’s two viable black pixels and  if  it’s not the first pixel to be drawn, the next frontier pixel is the one that’s in the corner or if the pixels aren’t touching each other  it’s  the one with  the  least number of  line  coloured neighbour pixels 

18  

Page 30: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

(see code snippet in fig. 14) unless none of them is located in a corner in which case it’s the one with the biggest number of inner coloured neighbour pixels. And the case where there’s two or even three viable black pixels, and being the first pixel to be drawn, the next pixel is the leftmost one. At the end, there’s only the possibility of no viable black pixel present and it’s the first pixel to be drawn, where it could mean that the frontier is ahead of this point. So the program sets the x coordinate as x+1, paints the lower debris coloured pixels back to back, if there’s any, paints white the previously floodfilled outer area pixel (which coloured the area) and search for the next black pixel again along the pixel line. 

 Figure 14:  code  snippet  from  the next pixel Boolean  statements  that,  in  case of  two  viable black 

neighbour pixels, selects the pixel in the corner or the one with the least number of line coloured neighbour pixels. In  the main  if/ else  statement,  the  first  statement  searches  for one of  the viable black pixels  in  the up  right or down  left corners and  the  second  in  the up  left or down  right corners. Then in each of the statements, it searches for the position of the other one and sets the position of the next pixel. 

 

   

19  

Page 31: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 15: code diagram  for  finding  the next  frontier pixel. Blue arrows and  rectangles are output 

values/actions; black arrow and rectangles are Boolean statement. 

20  

Page 32: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Now that the program has the position of the next pixel and if it’s not the case where it  floodfilled all  the white pixels or  set  the x  to x+1,  it paints all  the black pixels with  the debris colour, sets the coordinates  for the next pixel  (see code snippet  in  fig. 16), put the frontier pixel in the temporary area image, increment the counting of drawn pixels (only for the first four) and paints the next pixel with line colour. 

 

Figure 16: code snippet  to convert  the array  position  of  the  next pixel  to  (x,y)  coordinates. Each neighbour pixel has  its position in the array as: 

0  1  2 3  4  5 6  7  8 

To account for possible errors that could occur such as stranded lines or even closed line loops which could appear while it searches for a frontier, the program has to find if it’s running  the  line  in  a  counter  clockwise motion,  as  it  should,  or  not.  To  do  this, when  it reaches a point in the line where the y coordinate is the same as the initial one, it compares the x value with the initial one. If it’s bigger, then it means that the program is running in a clockwise motion along  the  line, meaning  that  it’s one of  those errors and  the analysis of this  frontier must stop and  the program must search again  for  the  real  frontier along  the pixel line. At this point, the program also paints this final pixel black, turns the initial pixel to line  colour,  to  be  floodfilled  later  with  black,  and  fills  the  possible  hole  with  white  by searching for the closest outer coloured pixel and floodfills it. Also the temporary blank area image is discarded. 

If  the next pixel  is  the  initial coloured one,  the program stops  the analysis  for  this frontier and starts the search  for the next one  (if  it’s not the third), paints the  initial pixel with  line  colour,  floodfills  it with debris  colour,  records  its position  to be  floodfilled with black later on and puts the temporary blank area image, now with the complete frontier line drawn, in the actual area image which is used to calculate all the data. 

After  all  the  frontiers  have  been  found,  the  program  clears  all  the  areas  back  to white  by  floodfilling  the white  area with  the  black  area  colour,  the  black  area with  the yellow area colour  then with  the exterior area colour and  finally with white. Note  that all this floodfillings were 8‐connected in order to cross the lines to the neighbouring areas. The program also  floodfills the areas  in each area  images with black and  ,for the wing  images, adds each eyespot area to its corresponding area image. 

21  

Page 33: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

For the data results, the program uses the ‘analyze’ function of the imageJ to obtain the area, diameters, the angle of the fitted ellipse, the centroid and the roundness for each area.  The  value  for  the  yellow  area  and  the  one  for  the  black  area  is  calculated  by subtracting the previous area to it. 

After all this is applied to every eyespot present, the program shows each area image at  the bottom of  the  screen,  if  the user  chose  to  in  the  initial  second dialog, and  then  it starts  to write  the  results  table with  the data chosen by  the user. Each area will have  its corresponding name  to  identify  it amongst  the others, and when analysing a wing  image, each eyespot will  also have  its  label  to  identify  them. These  labels  are  set  as default  for wings with the normal number of eyespots: for “Forewing” images with two eyespots, their labels are  ‘A’ and  ‘P’  (anterior and posterior) and  for “Hindwing”  images,  their names are ‘H1’ to ‘H7’. For mutants with extra or less eyespots, they’re just labelled with numbers. The program  then proceeds  in  filling  the  table with  the values,  showing only  the ones  for  the eyespots selected. 

Another type of output  is the depictions of the eyespot(s). The program can return an  image drawn with the obtained frontiers (‘Colored original areas’) and an  image drawn with the elliptical depiction of the frontiers (‘Colored elliptical areas’). 

To make the  first, the program paints the yellow area with yellow and then makes another  image  that  is  the result of  the calculation between  this and  the black area  image using the bitwise operator AND (&). Then  it floodfills the background with a brown colour. To  make  the  elliptical  frontiers  image,  the  program  draws  the  ellipse  for  the  external frontier of the yellow area on a temporary blank image, rotating it to its position, and adds it to a final blank image which will have all the eyespots. When the program is making this, it’s also doing  the  same  for  the black area.  In  the end,  it  calculates another  image using  the bitwise operator AND (&) between these two, filling the background with the brown colour. Then the program does the same for the white areas with the only difference being the fact that the background of  the white area  image  is black and the calculation uses the bitwise operator OR (|) this time. It calculates then the final image using the bitwise operator OR (|) between the previous black, yellow and brown image and the white in black image. 

   

22  

Page 34: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Analysis of fluorescence microscopy images 

This  subsection  is  used  when  the  “Distal‐less”  or  “Engrailed”  option  is  selected during the first initial dialog. It’s the one that gives the user the cross sections of the eyespot and  its  data  (area,  roundness,  diameter  and  image  representation)  for  fluorescence microscopy eyespot images. 

Since  the  image  is composed by several dots  instead of being a continuous object, the program “joins” the points to obtain a certain continuity between them, without gaping holes or opened areas. This is accomplished by applying the ‘maximum’ filter present in the imageJ with  radius  set  to  five, which  is  then applied with a Gaussian blur with  the  same radius (fig. 17). The ‘maximum’ plugin does a dilation of the image by replacing each pixel in it with the largest pixel value in that pixel’s neighbourhood. The radius value used is a good neighbourhood  to  apply  the  filter due  to  the distance between  the dots:  a  smaller  value would leave gaps between the coloured points and a larger one would be too much, ruining the intensity of the object in study. 

 Figure 17:  left – original “Engrailed”  image; right – original  image after applying the maximum and 

Gaussian blur filters. Note how the object is continuous but maintaining a certain degree of variable intensity throughout it. 

Firstly, the program makes three copies of the image to calculate each area data (fig. 18).  To  the  first  one,  it  applies  the  maximum  and  Gaussian  process  described  above, followed by binarization,  to obtain  the whole eyespot area. To  the  second one,  it  simply binarizes the image, apply the close operator and then the erode operator until it only has the central area. Then it applies the dilate operator the number of times it did the erosion to revert  the  size of  the centre. And  to  the  third one,  it applies  the maximum and Gaussian process, transforms it into a binary image and then applies the outline function. After this, it eliminates  the  outer  frontier  of  the  object  to  obtain  the  intermediate  frontier  found  in “Engrailed” images. 

23  

Page 35: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 

 Figure 18: top left – original “Engrailed” image; top right – the whole eyespot area; 

down left – the central area; down right – the intermediate frontier. 

When  the  program  has  these  three  images,  it  analyses  them  with  the  ‘analyze’ function of the imageJ, eliminating the smallest areas from the table in the case of the outer and  the  intermediate  frontiers. The  inner  area will have  its  area  value  subtracted by  the centre area. After this, the program puts the wanted data from each area inside the results table, each one  labelled as “Centre”, “Band” and “Whole” respectively  for  the centre,  the band around the centre if it’s an “Engrailed” image and the whole eyespot area. 

For  the cross  sections,  the program acquires  the brightness portion of  the original image and applies the maximum and Gaussian process to it. Because the imageJ cannot get the intensity cross sections unless they’re horizontal or vertical to the image, the image has to be rotated. And to avoid loosing information of the image, such as the corners, the image is then copied and centred by the centroid of the central area to another blank image with the diagonal of the original image as its width and height dimensions. 

To  make  the  average  cross  section,  the  program  calculates  an  average  image between eight copies of the same, each rotated by 45 degrees from the previous one (fig. 

24  

Page 36: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

20). Since the imageJ can only make image calculations between two images at a time, the global average  for n  images had  to be made with  the equation bellow, after  the average between  the  first  two,  in which Av(n‐2)  is  the  previous  average  and  n  the  number  of  the image. 

1      

To make the widest cross section and the shortest cut section, the program rotates the  images accordingly so  that  the widest or  the shortest diameter,  respectively,  is  in  the horizontal position. 

 Figure 20: left – treated image; right – average image from rotating the left one. 

After all these rotations and averages, the program sets the horizontal cross section as long as 5/4 of the maximum diameter of the outer frontier and as wide as the maximum diameter of the inner frontier. The result is a graphical representation of the pixel intensities (ranging from 0 to 255) across this section. 

It  is also possible  to obtain an  image  representation of  the eyespot using elliptical representations of each frontier. The method used is similar to the previously described for normal eyespot images with some minor differences. 

In the end, the program returns the results table  if the user selected any data as a required output. 

 

25  

Page 37: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Auxiliary methods 

The auxiliary methods contains the previously mentioned findWhite and macroWork methods as well as the distance method that calculates the distance between two points, to assist the program  in  its calculations.  It contains also the dialog  listener method to change the scale input on the second initial dialog. 

   

26  

Page 38: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Results 

This  section  shows  some  output  examples  using  single  eyespot,  wing  and fluorescence microscopy images. 

“Single eyespot” image (wildtype) 

 Figure 21: a) Original single eyespot image. Image representations of the eyespot; 

b) original frontiers; c) elliptical representation of the frontiers. 

 

 

 Figure  22:  Results  table.  Top  panel  –  data  corresponding  to  area,  roundness,  diameters  and  the 

minor and major widths of the black and yellow areas; Bottom panel– data corresponding to the area ratios (ratio of a small area with a  larger area). 

 

27  

Page 39: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

“Hindwing” images 

Wildype hindwing 

Figure 23: Wildtype hindwing image analysis. left – original image (wildtype);  

centre – original frontiers; right – elliptical representations of the frontiers.   

Table I: results table with the data for each area of each eyespot. 

    

28  

Page 40: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

‘Bigeye’ mutant hindwing 

Figure 24: left – original image (bigeye mutant); centre – original frontiers;  

right – elliptical representations of the frontiers.   

Table II: results table with the data for each area of each eyespot. 

    

29  

Page 41: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

‘Frodo’ mutant hindwing 

Figure 26: left – original image (‘frodo’ mutant); centre – original frontiers;  

right – elliptical representations of the frontiers.   

Table III: results table with the data for each area of each eyespot. 

    

30  

Page 42: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Characterization of mutant phenotypes 

These  results can also be used  to compare each  type of wings as well as between each eyespot on the same wing in terms of areas and their ratios. The following graphics are some examples of possible data comparison. 

wildtype

bigeye

frodo

h1 h2 h3 h4 h5 h6 h7

 Figure 27: pie charts representing the distribution of each area for each eyespot of the three types of 

wings. 

 

0

0.01

0.02

0.03

0.04

0.05

0.06

1 2 3 4 5 6 7

ratio

eyespot

wildtype

bigeye

frodo

 Figure 28: white area / eyespot area ratio of each eyespot for the three types of wing. 

 

31  

Page 43: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

1 2 3 4 5 6 7

ratio

eyespot

wildtype

bigeye

frodo

 Figure 29: black area / eyespot area ratio of each eyespot for the three types of wing. 

 

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1 2 3 4 5 6 7

ratio

eyespot

wildtype

bigeye

frodo

 Figure 30: yellow area / eyespot area ratio of each eyespot for the three types of wing. 

In these graphics, we have the representations of the ratios between each area and the whole eyespot of each eyespot for the three types of wing: wildtype, bigeye and frodo. 

As it can be observed in the first plot, the white areas are the most difficult ones to use  for comparison due  to  their  small  size  that confers  them more errors  in  the analysis: there’s a  larger variation between the eyespots than  in the case of the other areas.  In the 

32  

Page 44: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

figures  29  and  30,  there’s  an  agreement  between  their  values.  It  can  be  noted  that  the wildtype  individual  has  its  values more  or  less  constant  between  each  eyespot, meaning that  all  the eyespots  are equal except  for  their  global  size, which points  to  the  fact  that there’s  a  union  between  them  on  what  concerns  their  formation.  For  the  mutant individuals, it can be observed that they have a wave‐like variation between their eyespots but in a different way for each area. In the case of the black one, the ratio decreases at the beginning  to  the  second or  third eyespot,  increases  towards  the  fifth and  then decreases again,  and  in  the  case  of  the  yellow  area,  the  variation  is  the  opposite.  This  is  a  very interesting fact to observe, which indicates that the variation made to the individual to turn him  into a mutant doesn’t apply equally  to all  the eyespots present on  the wing,  instead there’s some that suffers  it more than others. The fact that there’s opposite variations for each area must suggest that the mechanisms involved in the formation of each of the areas must be  linked  in a way that when one varies  in a certain way, e.g.  increasing  in size, the other  varies  in  the  opposite way.  It  can  be  seen  as well  that  the  ‘bigeye’ mutant  is  the closest  to  the wildtype  in  terms  of  proportionalities  between  the  areas  of  the  eyespots, contrary to the ‘frodo’ mutant which has smaller black areas and bigger yellow ones. 

All  these data and more can clearly provide a deeper  insight  into  the mechanisms behind the formation of the eyespots, whether individually or in unison on a wing, as well as supply its study with new paths to approach. 

   

33  

Page 45: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

“Engrailed” image 

Wildtype 

 Figure 31: left – original “Engrailed” image; right – image representations of the areas. 

  

a)

b) c)

 Figure 32: a) average cross section; b) widest cross section; c) shortest cross section. 

34  

Page 46: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Mutant 

 Figure 33: left – original “Engrailed” image (mutant); 

right – image representations of the areas. 

a)

b) c)

 Figure 34: : a) average cross section. b) widest cross section.; c) shortest cross section. 

 

 

35  

Page 47: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Table IV: results table with the “Engrailed” image (wildtype) data. Label  Area  Roundness MinorAxis MajorAxis Engrailed ‐ Centre area  756  0.862  28.803  33.42 Engrailed ‐ Band area  28365 0.838  128.702  153.647 Engrailed ‐ Whole area  43896 0.926  227.467  245.707 

 

Table V: results table with the “Engrailed” image (mutant) data. Label  Area  Roundness  MinorAxis  MajorAxis Distal‐less ‐ Centre area  1019  0.833  32.865  39.477 Distal‐less ‐ Whole area  34974  0.991  210.039  212.009 

  

As  it can be observed, the engrailed mutant doesn’t have a doughnut shaped outer area.  Instead,  all  the  eyespot  expresses  the  protein,  and  to  analyse  this  image,  the  best method  to  use  is  the  “Distal‐less”  type  of  image  option,  even  though  it’s  an  “Engrailed” image,  i.e.  it’s  similar  to a Distal‐less expression  image. This method  is used because  the “Distal‐less” one analyses  the eyespot assuming  that  the  image has only  the  central area and the whole eyespot area whereas the “Engrailed” method assumes that the image has a doughnut  shaped  outer  area  besides  the  central  one.  Another  way  that  could  be implemented  in  the  future  is  to make only one method  for  the  fluorescence microscopy images  and  ask  the user  if  the eyespot has  a  ring  shaped outer  area or  if  the protein  is expressed  in  the whole eyespot. This way,  the mutants  could be analysed by  the  correct method instead of using the method of other type of expression. 

By  looking at the cross sections of the mutant,  it can be noted that there’s a small decrease of intensity near the central area, indicating that although it’s a mutant, the effect is not all effective on  the whole eyespot, a characteristic  that can be measured using  the values obtained from these graphics. Also, it’s possible to get the values and the position of the highest peaks of intensity that could be used to measure the distance between them in order  to  compare  with  other  individuals.  These  points  can  be  used  as  well  to make  a quantitative  analysis  of  the  intensity  variations.  With  the  values,  it  can  be  noted  and calculated using the intensity values that the highest density central point is approximately 12.6  times more  intense  than  the average  lowest point  inside  the eyespot and 1.2  times more intense than the average highest point of the ring area in the case of the wildtype and 1.46 and 1.25 respectively  for  the mutant.  In  this  latter case,  it can be observed with  this numbers that it’s possible to quantify the slight difference in the decrease of intensity near the centre of the eyespot, being the highest intensity average for the surrounding area 1.17 times higher than the depression. 

Another type of analysis that could be made using the data obtained from this types of  image  is  the  comparison  of  this  data  with  the  corresponding  formed  eyespot.  The problem is that the wing is damaged for the process of fluorescence and there’s no way to 

36  

Page 48: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

obtain  images  from the  final  formed wing with the eyespot  intact.  Instead, one thing that could be made is to make the fluorescence microscopy analysis with one wing and allow the individual to survive in order to see the other wing with the corresponding eyespot. It would give  a  good  substitute  for  the  actual  eyespot  that was marked  due  to  the  symmetry  of individuals, i.e. each wing is a mirror image of the other. This type of analysis would be most useful to the study of the formation of the eyespots, giving an insight on the corresponding cells that expressed a certain protein and the actual cells that give origin to a scale from a particular area. 

For a better analysis of these type of images, a good pre‐treatment is required, such as the removal of the background noise, so that the program doesn’t confuse this noise with the  actual  protein  expression.  Even  though  the  removal  of  the  said  noise would  help  in making  a  better  analysis  of  the  image,  it  causes  some  problems  to  it, mainly  the  cross section plots would become very small, i.e. the intensity decreases with the noise removal. It  could  help  but  ultimately  the  best  images  to  use  are  those  that  have  well  defined expression of  the protein, or else  the  low  intensity and  the background noise could make the image a bit undefined for the program to get proper plots of intensity. 

   

37  

Page 49: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

   

38  

Page 50: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Discussion 

The approach of acquiring  the eyespot  frontiers proved  to be  the best  to separate each of  their areas. Although  it could have  some  flaws and be prone  to  some errors,  the plugin is relatively strong to a certain amount of noise which could be present on the image and provides the user with detailed useful data. 

In  order  to  provide  good  and  meaningful  data  to  research,  mainly  to  make  a connection  between  what  is  being  changed  and  what  is  formed,  the  values  of  area, diameters  and  roundness  are  possible  to  obtain.  This  last  one  is  preferred  to  circularity because it’s a more significant value to the study; the circularity depends on the perimeter of the particle (4π*area/perimeter^2) whereas the roundness just depends on the major axis (4*area/(π*major_axis^2)).  By  not  depending  on  the  perimeter,  the  roundness  gives  us  a more correct value for how much close the particle is to a perfect circle, while the circularity would give us a value for how much close the frontier of the particle is to a smooth regular line. 

In  the  following  subchapters,  I  discuss  the  first  failed  method  and  the  current successful method  that were used  to resolve  the biological problem at hand, which  is  the quantitative analysis of the eyespot in certain types of image, in terms of effectiveness and reliability, as well as its problems and difficulties regarding its construction. After the latter method I discuss the prospects and possible advances for the future of the program. 

 

   

39  

Page 51: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Initial approach 

Prior to the use of this method which obtains the frontiers between each different area of the eyespot, another approach was initially thought of. This previously used method consisted  in obtaining  four or even  five colours  that would be  identified as each coloured area, three for the eyespot and one or possibly two for the rest of the wing. Basically, this process consisted in obtaining the value of each pixel on the image and plot them in a three dimensional  RGB  space  plot.  Then,  the  program would  search  for  four  or  five  clouds  of points: one in the white section, another in the black and another in the yellow and one or two  in  the  brown  section. With  these  clouds,  the  program would  find  their  centre  and calculate a neighbourhood around them; those points that were inside it, would correspond to  the area corresponding  to  that colour,  thus allowing  the program  to know which pixel belongs to each area. After obtaining the values for each pixel, they were plotted as shown in the figure 35. 

As  it can be observed, there aren’t the expected rounded clouds of points,  instead there’s some clouds of points around certain lines and to make things more complicated, it appears  that  the  yellow  portion  is  very  similar  to  the  brown  one,  practically  merged together and very difficult to separate, either manually or automatically. Therefore, this idea was abandoned in favour of the one that the plugin is actually based on, as the separation of each coloured areas by finding their colour doesn’t seem to work as expected. Also, it would work well on images with too much light, making the yellow area resembling the brown of the rest of the wing. 

 

40  

Page 52: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 

 Figure 35: top left – drawn model of two eyespots; top right – real image of an eyespot. 

Bottom – RGB space with every pixel represented by its colour. As  it  can  be  observed  on  the  left  graphic,  it was  expected  four  clouds  of  points:  black, brown, yellow, white. The graphic on the right it can be observed that the clouds are in the form of lines and for some images the difference between the yellow and the brown areas aren’t distinguishable as we can, more or less, visually in this eyespot image. 

   

41  

Page 53: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Current approach 

Although the method used seems very straightforward and simple, it’s actually quite troublesome concerning all the possible errors that can occur during the processing of the frontiers.  All  the  possible  errors were  taken  into  account which makes  the  program  run properly, but if the image quality isn’t good, i.e. with huge definition which allows a person to see all the scales  individually or poor  light quality,  it causes the program either thinking that the scales’ outlines are the frontiers or not being able to see them, respectively. 

The current approach  to get each area of  the eyespot works well either  for  single eyespot or whole wing images, but it could also occur some errors in some types of images. In case of single eyespot  image,  if the user crops an eyespot which  is merged with others, the program won’t separate its yellow area from the others’. Instead, the user is advised to cut the entire portion where there’s the eyespot in question and its merged neighbours and select ‘Forewing’  image type. This way, the program will  isolate each eyespot and the user only has to select the eyespot to be analysed. Furthermore, even though the user makes a poorly isolated eyespot by cutting some part of the yellow region while cropping the image, the program has a safety feature for this by framing the image, as explained before, making the  program  sturdy  to  this  kind  of  error. Whole wing  images  don’t  have  these  types  of problems, the biggest problem could be the quality of the  image. One way that could help to make sure the quality of the image is the right one would’ve been to make the program analyse  it  and  if  there’s  an excessively high quality  image  it would decrease  its  size,  and would make the opposite to a poor quality image. This was attempted but it didn’t seem to solve the problem  in the case of excessive high quality  images, only  in  low quality ones. In this  latter  case,  the  user  can  look  at  the  outlined  image  and  choose  to  enlarge  it.  The program could also automate this process but there’s no reference for the visual quality of the image, i.e. if the lines are closed and separated from each other, in order to proceed in increasing  its size. Even  if we take  into account the distance between the first and the  last eyespot, the program could possibly have a point of reference to do  it, but  it would make the program too heavy and slow and thus not very efficient in terms of time. 

The  selection of each eyespot present on a wing  image  in order  to  separate  them could’ve been made in two different ways: automatically or manually. It was decided to use the former to allow for the program to be more precise and fast in case of very good images to process, with  the eyespots’  centre well defined, even  though  this process  couldn’t be fully  automated  because  of  not‐so‐good  images.  As  explained  before,  if  the white  areas found aren’t the correct ones or there’s more white spots than the actual eyespots number, the user has to select the correct eyespots and thus the eyespot selection becomes manual. A complete manual selection could have been implemented and the program would search for the eyespot  in the vicinity of each selected points but  it would be  time consuming  for several images that could have a good quality to be analysed, and so the pseudo‐automatic method was chosen which helps the user in some if not most of the cases. 

42  

Page 54: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Another approach was attempted which consisted in an algorithm that would search the image for circular objects with a certain radius and count them. If there wasn’t enough, it would increase the radius and analyse the image again, and would keep doing this until all the eyespots were found. Although this seems a more precise method,  it turned out to be quite  inefficient  in terms of time, as each  iteration took a  lot of time to run and the whole process  several minutes  for  simple  small  testing  images.  In  the  future,  a more  efficient algorithm could be made to find even eyespots without the central white area. 

After  the  centre  of  each  eyespot  is  found,  the  program  goes  along  a  virtual  line between each eyespot, starting at each one, searching  for the  frontier between  the areas black  and  yellow.  These  distances  allows  the  program  to  find  the  point  between  them where the dividing line’s going to pass which is going to be at an angle to the virtual line. As it can be observed, this point isn’t equidistant from each of those frontiers. Instead, it’s near the  frontier  dividing  the  yellow  and  black  areas  of  the  biggest  eyespot  and  a  ratio  is calculated  to  find  the point. Because  the eyespots have  the  same developmental basis,  it would be expected that this condition would be applied to all of them, but it seems that the lines between the eyespot five, six and seven (and eight if it’s a mutant with an extra lower eyespot)  have  a  closer  resemblance  to  the  veins  separating  them  when  this  point  is equidistant from each of those black/yellow frontiers. Also, it could be observed that if the dividing  lines are perpendicular  to  their  corresponding  virtual  line between  the eyespots, they don’t mimic the position of the veins in that terminal area of the wing and end up not dividing the eyespots correctly, cutting parts that should belong to the other or giving the eyespot more yellow area  than  it  should. So, as  the wing  radiates  from a point  that  isn’t central to  it and the distance of each eyespot to this point  increases the  lower  it  is on the wing,  a  new  approach  was  taken.  Instead  of  making  the  lines  perpendicular  to  the corresponding  virtual  line,  the  program  would  make  it  perpendicular  to  a  virtual  line between  the  upper  eyespot  and  another  one  further  down.  After  some  testing  and experimenting, the following pairing was used: first with fifth, second with fifth, third with sixth, forth with seventh, and sixth with seventh for the  last  lines. As  it can be observed  in figure 36, the dividing lines using this method have a closer resemblance to the real veins in the area between each eyespot than the other method, making a more accurate division. 

43  

Page 55: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

 Figure 36: centre – normal hind wing image; 

left – outlined image with the dividing lines with the alternative method; right – outlined image with the dividing lines without the alternative method. 

Although  these  lines  seem  to  divide  the  eyespots  at  the  correct  boundary,  the division  between  the  first  and  the  second  eyespot  seems  to  be  better  in  the  normal perpendicular way  to  the virtual  line between both eyespots. Even  though  the other  line mimics better  the vein,  it seems  that  the  first eyespot’s yellow area  ‘bled’  through  to  the second eyespot zone beyond the supposedly  limiting vein. The current thought  is that the veins separates  the eyespots and  limits  their development but  it seems  that  the eyespots could  trespass  the  veins  if  they’re  bigger  than  their  supposedly  restricted  area.  It’s  only observed  in the case between the first and the second eyespot because  in the other cases where there’s merging of the yellow areas, the eyespots are facing each other with the vein right  between  them  and  in  this  case  the  eyespots  aren’t  directly  in  front  of  the  other, they’re not in the same position regarding the vein. Further experimental studies have to be made in order to test this hypothesis and if it turns out to be confirmed, the program will be modified to accommodate this situation. 

When  analysing  the  individual eyespots present  in  a wing  image, even  if  the user only wants  the  results  for  some particular eyespots,  the program analyses all of  them  to simplify  the  way  it  returns  the  values  in  a  table  and  to  enable  the  creation  of  the 

44  

Page 56: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

representative images. Perhaps if it proved to be better to only analyse the specific eyespots or  all  of  them  in  case  the  user wants  the  representative  images,  the  program  could  be modified to that effect. 

Obtaining the frontiers dividing each area from the others has some problems when the eyespot isn’t well defined, i.e. with the frontiers separated from each other and closed on themselves. One of the problems it raises is the fact that the program uses as a reference the colours of the areas on each side of the line, and when analysing a black/ yellow frontier that’s glued  to  the yellow/ external one,  for example,  the program will paint  the external area with the yellow area colour and thus when  it’s going to search  for the outer  frontier between the yellow and the external area,  it doesn’t find  it because the exterior  is already painted with the yellow colour, and so the program doesn’t get this next frontier. Another problem  that  could happen  to  certain  images  is when  the black/  yellow  frontier  and  the yellow/ external one are one by having gaps  that  links  the black area  to  the exterior, and thus the program only finds one (or none if the search pathway passes right through one of those gaps) and misses the other. All this problems is due to the poor quality of the images, either with too much  light over  it, making the yellow colour much  like the brown external colour, fading the frontier between them, or a small image where the yellow area is so thin in  some  zones  that  the  program  draws  only  one  line  separating  the  black  area  and  the exterior.  It  could  also  occur  that  the  vein  that  goes  through  the  eyespots  could  be  so pronounced that the program outlines them as well, uniting the black area with the exterior with a gap. 

The  other  type  of  images  possible  to  be  analysed  are  fluorescence  microscopy images where a certain protein expression  is represented by a collection of dots  in a black background. This type of images don’t give us a solid well defined object because these dots are separated from each other, forming a dispersed object. To get around this problem, the approach used was  to dilate  the points until  they  touched each other, giving  the object a solid closed appearance. After  this  is done,  the eyespot can  then be outlined  to calculate their  dimensions  and  area  as well  as  be  ready  to  obtain  cross  sections  of  it  through  its middle. Without this dilation, these would become not a smooth line with three maximums but a  jagged  line with  several peaks. Although  this method works well  to acquire a  solid eyespot  to analyse,  it  is prone  to  some error  in  the  results because  the original  image  is modified and  the  final  results are  from  the adapted  image and not  from  the original one. But  comparing  the  result  image  and  the  original,  there’s  a  very  close  approximation between them, making this method suitable for the analysis needed (figure 17). 

The average cross section through the modified image isn’t as accurate as the widest and shortest cross sections because the calculation of the average image gives us a slightly less  intense  image  than  it would  be  in  reality  by  around  2%.  This  happens  because  the calculation  between  images  is  done  by  just  returning  the  integer  value,  discarding  the decimal part and  thus  sometimes  the pixel would have more or  less one  from  the actual 

45  

Page 57: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

value,  never  cancelling  itself  out.  This  would  be  attenuated  if  it  would  be  possible  to calculate  the average with all  the  images at  the same  time which  is not possible with  the software. The calculation could be made by getting  the pixels  from all of  the  images and then return one with the average values, but it would take to much time for the program to run it and it wouldn’t be practical. It’s always best to use the functions of imageJ instead of writing new ones, they’re fastest to run. 

 

Future developments 

Even  though  this  program  gives  us  detailed  data  on  each  of  the  areas  of  the eyespots, some of them not available before, it has room for more possible outputs as the study of  these butterflies  increases and demands  for other  types of data.  In  the  future, a more general program will be created that could analyse all sorts of images with continuous closed loops to be analysed. This program will have different types of labelling of the areas as well  as  other  possible  interesting  parameters,  such  as  the  circularity,  and will  have  a different method/algorithm to find the patterns to be analysed. 

Furthermore, as mentioned before, a new way to find the eyespots must be made in order  to  be  able  to  analyse  even  the mutant  individuals without  the  central white  area present on the eyespots, and, for mutants with the black areas merged together or without them at all, some alterations to the rules and method to follow the frontiers must be made as well,  also  to  help  bypass  the  problem with  the  image  quality  concerning  the merged black/yellow and  yellow/external area  frontiers or  the gaps  that  could occur  through  the yellow area. 

All  in all,  there’s  still much enhancing  that  could be done  to  the program but  the current plugin  is  still  the best  tool  to do  the analysis of  the eyespot patterns and a great asset  to  help  continue  the  studies  on  the  evolution  and  development  model  Bicyclus anynana  with  more  precise  data  that  will  provide  a  quantitative  comparison  between phenotypic variation and gene expression. 

   

46  

Page 58: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

References 

(1) Beldade P, Brakefield PM, Long AD (2005) ‘Generating phenotypic variation: prospects from "evo‐devo" research on Bicyclus anynana wing patterns’. Evol. Dev 7:101‐107. 

(2) Beldade P, Brakefield PM (2003) ‘Concerted evolution and developmental integration in modular butterfly wing patterns’. Evol. Dev 5:169‐179. 

(3)  Beldade  P,  Rudd  S, Gruber  JD,  Long AD  (2006)  ‘A wing  expressed  sequence  tag  resource  for Bicyclus anynana butterflies, an evo‐devo model’. BMC Genomics 7:130. 

(4) Saenko SV, Brakefield PM, Beldade P (2010) ‘Single locus affects embryonic segment polarity and multiple aspects of an adult evolutionary novelty’. BMC Biol 8:111. 

(5) Allen CE, Beldade P, Zwaan BJ, Brakefield PM  (2008)  ‘Differences  in  the  selection  response of serially  repeated  color  pattern  characters:  standing  variation,  development,  and  evolution’.  BMC Evol. Biol 8:94. 

(6)  Beldade  P,  French  V,  Brakefield  PM  (2008)  ‘Developmental  and  genetic  mechanisms  for evolutionary  diversification  of  serial  repeats:  eyespot  size  in Bicyclus  anynana  butterflies’.  J.  Exp. Zool. B Mol. Dev. Evol 310:191‐201. 

(7) Beldade P, Koops K, Brakefield PM  (2002)  ‘Modularity,  individuality, and evo‐devo  in butterfly wings’. Proc. Natl. Acad. Sci. U.S.A 99:14262‐14267. 

(8)  Silveira M, Monteiro  A  (2009)  ‘Automatic  recognition  and measurement  of  butterfly  eyespot patterns’. BioSystems 95:130‐136. 

(9) Dilão R, Sainhas  J  (2004)  ‘Modelling butterfly wing eyespot patterns’. Proc. Biol. Sci 271:1565‐1569. 

(10)  Evans  TM,  Marcus  JM  (2006)  ‘A  simulation  study  of  the  genetic  regulatory  hierarchy  for butterfly eyespot focus determination’. Evol. Dev 8:273‐283. 

(11) Monteiro  A,  French  V,  Smit  G,  Brakefield  PM, Metz  JA  (2001)  ‘Butterfly  eyespot  patterns: evidence for specification by a morphogen diffusion gradient’. Acta Biotheor 49:77‐88. 

(12) Beldade P, Brakefield PM  (2002)  ‘The genetics and evo‐devo of butterfly wing patterns’. Nat. Rev. Genet 3:442‐452. 

(13) Brakefield PM et al. (1996) ‘Development, plasticity and evolution of butterfly eyespot patterns’. Nature 384:236‐242. 

(14) Beldade P, Saenko SV, Pul N, Long AD  (2009)  ‘A gene‐based  linkage map for Bicyclus anynana butterflies allows for a comprehensive analysis of synteny with the lepidopteran reference genome’. PLoS Genet 5:e1000366. 

(15)  Rasband,  W.S.,  ImageJ,  U.  S.  National  Institutes  of  Health,  Bethesda,  Maryland,  USA, http://imagej.nih.gov/ij/, 1997‐2011.   

47  

Page 59: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

   

48  

Page 60: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

Annexes 

Variables 

Some of  the variables used  in  the program are  listed here  to  facilitate  its  reading. Others are explained it the code as well. 

size  enlargement factor of the copied image to be analysed; 

imgTp  type  of  image  to  analyse:  "Single  Eyespot",  "Forewing",  "Hindwing", "Distal‐less", "Engrailed"; 

nrEyes  number of eyespots to analyse;

scale  scale of the image;

analyse  the eyespots to analyse;

ratios  list of chosen areas to calculate area ratios;

selectedAreas  list of areas to be analysed;

drawOriginal  draw a representative image with the original frontiers; 

drawEllipses  draw a representative image with ellipses of the frontiers; 

showArea  return the area value;

showRoundness  return the roundness value;

showDiameters  return the diameters values (minorAxis – smallest diameter; majorAxis – largest diameter); 

showAreas  display each area separately;

avgCutSection  return the average cross section;

widCutSection  return the widdest cross section;

shrCutSection  return the shortest cross section;

m  list of slopes of each line that separate the eyespots; 

b  list of y‐intercept of each line that separate the eyespots; 

interPoint  list of coordinates of the crossing points for the dividing lines between the eyespots; 

49  

Page 61: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

eyesCoord  list of coordinates for each eyespot;

ipLines  imageprocessor (binary image) with the frontiers and the dividing lines (when applicable); 

whiteCoord  list of coordinates for the centre of the eyespot;

paintAreas  list  of  coordinates  for  each  area  for  each  eyespot  (x.white,  y.white, x.black, y.black, x.yellow, y.yellow); 

eyespot  the eyespot to analyse;

ff  floodfiller for the ipLines;

colors  list of color values: white area, black area, yellow area, exterior color, debris color, line color, initial pixel; 

borderCount  frontier to find (1‐3);

paintLinesBlack  list of coordinates to paint the frontiers black;

getEyesF  list of eyespots to be analysed on forewing;

getEyesH  list of eyespots to be analysed on hindwing;

listener  standard  number  of  eyespots:  single  eyespot  =  1,  forewing  =  2, hindwing = 7, distal‐less = 1, engrailed = 1; 

viablePix  list of the weight values for each of the current pixel neighbours;

newCoord  position in the neighbour grid of the next coordinate; 

minColorIn  position in the neighbour grid of the pixel with the smallest number of neighbours with inner area colour; 

minColorLine  position in the neighbour grid of the pixel with the smallest number of neighbours with line colour; 

initX  x coordinate of the frontier initial pixel;

initY  y coordinate of the frontier initial pixel;

passY  variable to mark the passage through the initY value; 

area  list of the area values of each area for each eyespot; 

minAxis  list of the minorAxis values of each area for each eyespot; 

50  

Page 62: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

51  

majAxis  list of the MajorAxis values of each area for each eyespot; 

axisAngle  list of the fitted ellipse angles of each frontier for each eyespot; 

xCentroid  list of the centroid x position of each area for each eyespot; 

yCentroid  list of the centroid y position of each area for each eyespot; 

roundNess  list of the roundness values of each area for each eyespot; 

sufixEye  list of the names for each eyespot;

analyseEyes  list of the eyespots to analyse;

images  number of opened images to analyse (all or just the current one);

paletteDec  list of colours to colorize the image representations; 

angle  angle for the image rotation to perform the average calculation; 

nrLayers  number of images to use in the average calculation; 

palette  list  of  colours  to  colorize  the  image  representations  (fluorescence microscopy images); 

rtAreas  final results table;

findWhite  method to find a white pixel from the central spot; 

macroWork  method to binary treat the image (frontier outlines); 

distance  method to calculate the distance between two points; 

 

   

Page 63: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

1  

 

 

 

 

 

 

 

Program Code   

Page 64: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

2  

import ij.*; import ij.gui.*; import ij.measure.*; import ij.plugin.*; import ij.plugin.filter.*; import ij.plugin.frame.*; import ij.process.*; import java.awt.*; import java.util.Arrays; import ij.gui.DialogListener; import java.awt.AWTEvent; public class eyespotAnalysis_ implements PlugInFilter, Measurements, DialogListener { ImagePlus imp; int listener; int imgTp; int size; public int setup(String arg, ImagePlus imp) { if (arg.equals("about")) { showAbout(); return DONE; } this.imp = imp; return DOES_ALL; } void showAbout(){ IJ.showMessage("About eyespotAnalysis...", "This plugInFilter analyses the eyespot wing patterns from Bicyclus anynana in terms\n"+ "of color quantification, size and proporcionalities between its different areas.\n"+ "It also analyses fluorescent microscopy images"); } public void run(ImageProcessor ip) { // <<-- GenericDialog -->> String[] imgTypes = {"Single Eyespot","Forewing","Hindwing","Distal-less","Engrailed"}; GenericDialog gdImg = new GenericDialog("Eyespot Analysis - Image Type"); gdImg.addChoice("Type of image to analyse ", imgTypes, "Single Eyespot"); gdImg.showDialog(); if (gdImg.wasCanceled()) return; imgTp = gdImg.getNextChoiceIndex(); int nrEyes = (int)((4.0/3)*Math.pow(imgTp,4)-(21.0/2)*Math.pow(imgTp,3)+(145.0/6)*Math.pow(imgTp,2)-14*imgTp+1); listener = nrEyes; double scale = 1; //scale to use on output measurements boolean[] ratios = {false, false, false, false}; //use for ratios: eyespot, white, black, yellow String[] labelsAreas = {"Eyespot", "White", "Black", "Yellow"};

Page 65: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

3  

boolean[] selectedAreas = {true, false, false, false}; //areas to study: eyespot, white, black, yellow String[] labelsCalc = {"Area", "Eyespot", "Colored original areas", "Roundness", "White", "Colored elliptical areas", "Diameters", "Black", "", "", "Yellow", "Analyse all images"}; boolean[] getCalc = {true, false, false, false, false, false, false, false, false, false, false, false}; String[] headingsCalc = {"Measurements", "Areas ratios", "Drawing the eyespot"}; String analyse = "all"; String[] labelsCalcPts = {"Area", "Average cross section", "Colored elliptical areas", "Roundness", "Widest cross section", "", "Diameters", "Shortest cross section", "Analyse all images"}; boolean[] getCalcPts = {false, true, false, false, false, false, false, false, false}; String[] headingsCalcPts = {"Measurements", "Cross sections", "Drawing the eyespot"}; int point = 0; int calcData = 0; int areasCount = 0; int ratiosNr = 0; boolean showArea = false; boolean showRoundness = false; boolean showDiameters = false; boolean drawOriginal = false; boolean drawEllipses = false; boolean showAreas = false; boolean avgCutSection = true; boolean widCutSection = false; boolean shrCutSection = false; boolean allImgs = false; boolean showLines = false; boolean scaleIJ = true; boolean sDialog = true; while(sDialog){ //make the starting generic dialog GenericDialog gd = new GenericDialog("Eyespot Analysis"); if(imgTp == 1 || imgTp == 2){ gd.setInsets(10,0,0); gd.addNumericField("Number of Eyespots on the wing:", nrEyes, 0, 2, "Eyespots"); gd.addStringField("Eyespots to analyse: ", analyse, 13); gd.setInsets(0,195,0); gd.addMessage("( use 'all' or numbers separated with - )"); gd.setInsets(10,10,20); gd.addMessage("_____________________________________________________________"); gd.setInsets(0,20,0); } if(imgTp < 3){ Font font = new Font ("Verdana", Font.BOLD, 12); gd.addMessage("Select which areas to study", font); gd.setInsets(15,90,0); gd.addCheckboxGroup(1, 4, labelsAreas, selectedAreas); gd.setInsets(10,10,25); gd.addMessage("_____________________________________________________________"); gd.setInsets(0,68*imgTp-34*imgTp*(imgTp-1),0);

Page 66: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

4  

} else{ gd.setInsets(10,0,0); } gd.addCheckbox("Use image scale", scaleIJ); if(imgTp != 1 && imgTp != 2) gd.setInsets(10,14,20); else gd.setInsets(10,0,20); gd.addNumericField("Set manual scale:", scale, 2, 10, "pixels/mm"); ((TextField) gd.getNumericFields().get((int)(imgTp*(1+(imgTp-1)*((double)(imgTp-2)*(imgTp-4)/2-(double)(imgTp-3)*(imgTp-4)/4- (double)(imgTp-2)*(imgTp-3)/6))))).setEnabled(false); if(imgTp < 3){ gd.addCheckboxGroup(4, 3, labelsCalc, getCalc, headingsCalc); gd.setInsets(10,0,0); if(imgTp != 0){ gd.addCheckbox("Show image with the dividing lines", showLines); gd.setInsets(0,0,0); } gd.addCheckbox("Show images for each area", showAreas); } else{ gd.addCheckboxGroup(3, 3, labelsCalcPts, getCalcPts, headingsCalcPts); } gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) return; if(imgTp == 1 || imgTp == 2){ nrEyes = (int)gd.getNextNumber(); analyse = gd.getNextString(); } if(imgTp < 3){ for(int sl = 0; sl < selectedAreas.length; sl++) selectedAreas[sl] = gd.getNextBoolean(); } scaleIJ = gd.getNextBoolean(); scale = gd.getNextNumber(); if(scaleIJ) scale = 1; if(imgTp < 3){ showArea = gd.getNextBoolean(); getCalc[0] = showArea; ratios[0] = gd.getNextBoolean(); getCalc[1] = ratios[0]; drawOriginal = gd.getNextBoolean(); getCalc[2] = drawOriginal; showRoundness = gd.getNextBoolean(); getCalc[3] = showRoundness; ratios[1] = gd.getNextBoolean(); getCalc[4] = ratios[1]; drawEllipses = gd.getNextBoolean(); getCalc[5] = drawEllipses; showDiameters = gd.getNextBoolean(); getCalc[6] = showDiameters; ratios[2] = gd.getNextBoolean(); getCalc[7] = ratios[2]; ratios[3] = gd.getNextBoolean(); getCalc[10] = ratios[3]; allImgs = gd.getNextBoolean(); getCalc[11] = allImgs; if(imgTp != 0) showLines = gd.getNextBoolean();

Page 67: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

5  

showAreas = gd.getNextBoolean(); } else{ showArea = gd.getNextBoolean(); getCalcPts[0] = showArea; avgCutSection = gd.getNextBoolean(); getCalcPts[1] = avgCutSection; drawEllipses = gd.getNextBoolean(); getCalcPts[2] = drawEllipses; showRoundness = gd.getNextBoolean(); getCalcPts[3] = showRoundness; widCutSection = gd.getNextBoolean(); getCalcPts[4] = widCutSection; showDiameters = gd.getNextBoolean(); getCalcPts[6] = showDiameters; shrCutSection = gd.getNextBoolean(); getCalcPts[7] = shrCutSection; allImgs = gd.getNextBoolean(); getCalcPts[8] = allImgs; } calcData = 0; if(imgTp < 3){ for(int c = 0; c < getCalc.length-1; c++) if(getCalc[c] && c != 2 && c != 5) calcData++; } else{ for(int c = 0; c < getCalcPts.length-2; c++) if(getCalcPts[c] && c != 1 && c != 2 && c!= 4) calcData++; } areasCount = 0; for(int a = 0; a < selectedAreas.length; a++) if(selectedAreas[a]) areasCount++; ratiosNr = 0; for(int b = 0; b < ratios.length; b++) if(ratios[b]) ratiosNr++; int calc = 0; if(imgTp < 3){ for(int c = 0; c < getCalc.length-1; c++) if(getCalc[c]) calc++; } else{ for(int c = 0; c < getCalcPts.length-1; c++) if(getCalcPts[c]) calc++; } int falseEyes = analyse.length(); if(!(analyse.equalsIgnoreCase("all"))){ //check if each number inserted for analysis is correct falseEyes = -1; String analyseTmp = analyse+"-"; for(int d = 0; d < analyse.length(); d=d+2){ int e = 1; while(e <= 9){ if(analyseTmp.charAt(d) == e+48 && analyseTmp.charAt(d+1) == '-'){ falseEyes = falseEyes+2; e = 10; } else{ e++; } } } }

Page 68: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

6  

if(nrEyes < (analyse.length()+1)/2 && !(analyse.equalsIgnoreCase("all"))){ IJ.showMessage("Error", "A number bigger than the number of available eyespots was introduced for analysis."); } else if(falseEyes != analyse.length()){ IJ.showMessage("Error", "A wrong number for the eyespots to be analysed was introduced."); } else if(nrEyes <= 0){ IJ.showMessage("Error", "A wrong number of eyespots was introduced."); } else if(ratiosNr == 1 && imgTp < 3){ IJ.showMessage("Error", "Only one area to calculate area ratios was chosen."); } else if(ratiosNr > 1 && imgTp < 3){ int d = 1; boolean popup = false; while(d < 4){ if(ratios[d] != selectedAreas[d]){ YesNoCancelDialog confirm = new YesNoCancelDialog(IJ.getInstance(), "Confirm",

"At least one of your chosen areas to study isn't selected for area ratio analysis.\n\nDo you still want to proceed?");

if (confirm.yesPressed()) sDialog = false; popup = true; d = d + 4; } else{ d++; } } if(!popup) sDialog = false; } else if(areasCount == 0 && calcData != 0){ IJ.showMessage("Error", "Must choose an area to analyse."); } else if(calc == 0){ IJ.showMessage("Error", "Must choose some output data."); } else if(gd.invalidNumber()){ IJ.showMessage("Error", "The scale is not a number."); } else{ sDialog = false; } }//end of the GenericDialog ResultsTable rtAreas = new ResultsTable(); int[] listImgs = WindowManager.getIDList(); int nrImages = listImgs.length; if(!allImgs){ listImgs[0] = (WindowManager.getCurrentImage()).getID(); nrImages = 1; } for(int images = 1; images <= nrImages; images++){ //analysis of each opened image imp = WindowManager.getImage(listImgs[images-1]); ip = imp.getProcessor();

Page 69: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

7  

String nameEdited = (imp.getTitle()).substring(0,(imp.getTitle()).lastIndexOf(".")); int width = imp.getWidth(); int height = imp.getHeight(); Dimension dim = IJ.getScreenSize(); int dimWidth = dim.width; int dimHeight = dim.height; size = 1; ImageProcessor ipLines = new ByteProcessor(width, height); if(imgTp < 3) ipLines = macroWork(imp); //macro treatment of the image if(size != 1){ imp = new ImagePlus(imp.getTitle(), ip.resize(size*width)); ip = imp.getProcessor(); width = imp.getWidth(); height = imp.getHeight(); } int pixelLimit = 255; ImagePlus impLines = new ImagePlus(); // <<-------------------- separation of eyespots -------------------->> double[][] eyesCoord = new double[nrEyes][2]; //coordinates for each eyespot if(imgTp == 1 || imgTp == 2){ double[] m = new double[nrEyes]; double[] b = new double[nrEyes]; int[][] interPoint = new int[nrEyes][2]; //crossing point for the dividing lines ImageProcessor ipWingTemp = ip.convertToByte(true); ImagePlus impWingTemp = new ImagePlus(nameEdited+" - background.jpg",ipWingTemp); ImageProcessor ipWing = new ColorProcessor(width,height); ImagePlus impWing = new ImagePlus(); boolean[] corners = {false,false,false,false}; if(ipWingTemp.getPixel(0,0) >= 245) corners[0] = true; if(ipWingTemp.getPixel(width-1,0) >= 245) corners[1] = true; if(ipWingTemp.getPixel(width-1,height-1) >= 245) corners[2] = true; if(ipWingTemp.getPixel(0,height-1) >= 245) corners[3] = true; int cornerCounter = 0; for(int wh = 0; wh < corners.length; wh++) if(corners[wh]) cornerCounter++; //counting white corners if(cornerCounter > 0){ //if there's white corners ipWingTemp.setThreshold(0,128,1); IJ.run(impWingTemp, "Make Binary", "thresholded remaining black"); IJ.run(impWingTemp, "Close-", "");

Page 70: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

8  

IJ.run(impWingTemp, "Dilate", ""); //[corners -> 4+first][found black for each corner][X,Y coordinate for each black found] int[][][] cornerCoords = {{{0,-1},{-1,0}}, {{-1,0},{width-1,-1}}, {{width-1,-1},{-1,height-1}}, {{-1,height-1},{0,-1}},

{{0,-1},{-1,0}}}; //find the cornerCoords to make the lines to contain the figure for(int cr = 0; cr < corners.length; cr++){ int one = 1; boolean firstPoint = false; boolean secondPoint = false; if(corners[cr]){ while((!firstPoint || !secondPoint) && (one < width || one < height)){ int firstX = width-1; int firstY = height-1-one; int secondX = width-1-one; int secondY = height-1; if(cr%3 == 0){ firstX = 0; secondX = one; } if(cr < 2){ firstY = one; secondY = 0; } if(one < height && !firstPoint){ if(ipWingTemp.getPixel(firstX,firstY) == 0){ if(cr<2){ cornerCoords[cr][cr%2][1] = one; } else{ cornerCoords[cr][cr%2][1] = height-1-one; } firstPoint = true; } } else if(one == height && !firstPoint){ firstPoint = true; } if(one < width && !secondPoint){ if(ipWingTemp.getPixel(secondX,secondY) == 0){ if(cr%3 == 0){ cornerCoords[cr][1-(cr%2)][0] = one; } else{ cornerCoords[cr][1-(cr%2)][0] = width-1-one; } secondPoint = true; } } else if(one == width && !secondPoint){ secondPoint = true; }

Page 71: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

9  

one++; } } } cornerCoords[4][0][1] = cornerCoords[0][0][1]; cornerCoords[4][1][0] = cornerCoords[0][1][0]; //put black lines on the inside of the figure IJ.setForegroundColor(0,0,0); for(int wFrame = 0; wFrame < corners.length; wFrame++){ if(corners[wFrame]){ if(cornerCoords[wFrame][1][wFrame%2] != -1){ if(cornerCoords[wFrame+1][0][wFrame%2] != -1){ ipWingTemp.drawLine(cornerCoords[wFrame][1][0], cornerCoords[wFrame][1][1], cornerCoords[wFrame+1][0][0], cornerCoords[wFrame+1][0][1]); } else{ ipWingTemp.drawLine(cornerCoords[wFrame][1][0], cornerCoords[wFrame][1][1],

cornerCoords[wFrame+1][1-(wFrame%2)][0], cornerCoords[wFrame+1][wFrame%2][1]); } } } else if(cornerCoords[wFrame+1][0][wFrame%2] != -1){ ipWingTemp.drawLine(cornerCoords[wFrame][wFrame%2][0], cornerCoords[wFrame][1-(wFrame%2)][1], cornerCoords[wFrame+1][0][0], cornerCoords[wFrame+1][0][1]); } else{ ipWingTemp.drawLine(cornerCoords[wFrame][wFrame%2][0], cornerCoords[wFrame][1-(wFrame%2)][1], cornerCoords[wFrame+1][1-(wFrame%2)][0], cornerCoords[wFrame+1][wFrame%2][1]); } } IJ.run(impWingTemp, "Fill Holes", ""); ipWingTemp.invert(); ipWingTemp.setColor(0); ipWingTemp.drawRect(0,0,width,height); IJ.run(impWingTemp, "Dilate", ""); IJ.run(impWingTemp, "Dilate", ""); ImageCalculator icWhiteB = new ImageCalculator(); ImagePlus impNoWhiteB = icWhiteB.run("AND create", imp, impWingTemp); ipWing = impNoWhiteB.getProcessor(); impWing = new ImagePlus(nameEdited+" - background.jpg",ipWing); } else{ ipWing = ip; impWing = new ImagePlus(nameEdited+".jpg",ipWing); } //find the white areas int nEyes = nrEyes; ImageProcessor ipCountW = new ByteProcessor(width, height); ImagePlus impCountW = new ImagePlus(); int pixel = 0; int red = 0;

Page 72: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

10  

int green = 0; int blue = 0; ResultsTable rtEyes = new ResultsTable(); int options = ParticleAnalyzer.CLEAR_WORKSHEET+ParticleAnalyzer.INCLUDE_HOLES; int measurements = CENTROID; int minSize = 1; int maxSize = 9999999; ParticleAnalyzer paEyes = new ParticleAnalyzer(options, measurements, rtEyes, minSize, maxSize); //get each eyespot position pixelLimit = 255; int extraPts = 0; boolean findingAll = true; while(findingAll){ boolean finding = true; while(finding){ ipCountW = new ByteProcessor(width, height); ipCountW.invert(); impCountW = new ImagePlus(nameEdited+" - probable eyespots.jpg",ipCountW); for(int ys = 0; ys < height; ys++){ for(int xs = 0; xs < width; xs++){ pixel = ipWing.getPixel(xs,ys); red = (pixel & 0x00ff0000) >> 16; green = (pixel & 0x0000ff00) >> 8; blue = pixel & 0x000000ff; if(red >= pixelLimit && green >= pixelLimit && blue >= pixelLimit && ipCountW.getPixel(xs,ys) == 255) ipCountW.putPixel(xs,ys,0); } } IJ.run(impCountW, "Dilate", ""); //to remove possible white area splitted counting as two points and to aid in their visualization paEyes.analyze(impCountW, ipCountW); if(rtEyes.getCounter() >= nEyes){ finding = false; extraPts = rtEyes.getCounter()-nEyes; } else{ pixelLimit--; rtEyes.reset(); } } impCountW.show(); impCountW.getWindow().setLocation(100, 100); YesNoCancelDialog confirmTreat = new YesNoCancelDialog(IJ.getInstance(), "Confirm", "Are these the positions of ALL the Eyespots?\n \nIf not, press [No] to find the missing Eyespot(s).\nOr press [Cancel] to exit."); if (confirmTreat.yesPressed()){ impCountW.hide(); findingAll = false; } else if(confirmTreat.cancelPressed()){ impCountW.changes = false;

Page 73: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

11  

impCountW.close(); return; } else{ nEyes++; rtEyes.reset(); impCountW.changes = false; impCountW.close(); } } double[] xPtsCoord = rtEyes.getColumnAsDoubles(ResultsTable.X_CENTROID); //points found x double[] yPtsCoord = rtEyes.getColumnAsDoubles(ResultsTable.Y_CENTROID); //points found y double[][] ptsCoord = new double[xPtsCoord.length][2]; for(int merge = 0; merge < xPtsCoord.length; merge++){ ptsCoord[merge][0] = xPtsCoord[merge]; ptsCoord[merge][1] = yPtsCoord[merge]; } //dialog to eliminate the wrong "eyes" if(nEyes != nrEyes || extraPts != 0){ //if there's more points than the eyespots impCountW.show(); impCountW.getWindow().setLocation(100, 100); IJ.setTool("multipoint"); boolean noPoints = true; int[] xSelectedPts = new int[nrEyes]; //selected x points int[] ySelectedPts = new int[nrEyes]; //selected y points while(noPoints){ //user selected points input WaitForUserDialog wfud = new WaitForUserDialog("Select the Eyespots", "Select the "+nrEyes+" points corresponding to an Eyespot and then click OK."); wfud.show(); Roi roiPts = impCountW.getRoi(); if(roiPts == null){ IJ.showMessage("Error", nrEyes+" points must be chosen."); } else{ Polygon p = roiPts.getPolygon(); if(p.npoints != nrEyes){ if(p.npoints < nrEyes){ IJ.showMessage("Error", nrEyes+" points must be chosen."); } else{ int extra = p.npoints-nrEyes; IJ.showMessage("Error", "Extra "+extra+" points were selected. Only "+nrEyes+" points must be chosen."); IJ.run(impCountW, "Select None", ""); } } else{ noPoints = false; IJ.run(impCountW, "Select None", ""); IJ.runMacro("setTool(0)");

Page 74: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

12  

impCountW.hide(); for (int i = 0; i < p.npoints; i++){ xSelectedPts[i] = p.xpoints[i]; ySelectedPts[i] = p.ypoints[i]; } } } } for(int list = 0; list < xSelectedPts.length; list++){ //correspondence between selected and the eyespots double xNearest = ptsCoord[0][0]; double yNearest = ptsCoord[0][1]; double d1 = distance((double)xSelectedPts[list], (double)ySelectedPts[list], ptsCoord[0][0], ptsCoord[0][1]); for(int scanning = 1; scanning < xPtsCoord.length; scanning++){ double d2 = distance((double)xSelectedPts[list], (double)ySelectedPts[list], ptsCoord[scanning][0], ptsCoord[scanning][1]); if(d1 > d2){ xNearest = ptsCoord[scanning][0]; yNearest = ptsCoord[scanning][1]; d1 = d2; } } eyesCoord[list][0] = xNearest; eyesCoord[list][1] = yNearest; } } else{ eyesCoord = ptsCoord; } //sorting the array by the y coordinate -> wings must be in a vertical position, top side up for(int read = 0; read < nrEyes-1; read++){ double small = eyesCoord[read][1]; double other = eyesCoord[read+1][1]; int pos = read; for(int str = 1; str < nrEyes-read; str++){ if(small > other){ small = other; pos = read+str; } if(str < nrEyes-read-1) other = eyesCoord[read+str+1][1]; } double[] sub = eyesCoord[read]; eyesCoord[read] = eyesCoord[pos]; eyesCoord[pos] = sub; } if(nrEyes > 1){ //get the lines between each eyespot neighbor

Page 75: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

13  

ImageProcessor ipWingLines = new ByteProcessor(width,height); Duplicator duplicate = new Duplicator(); ImagePlus impSlices = duplicate.run(imp); IJ.run(impSlices, "HSB Stack", ""); ImageStack stack = impSlices.getStack(); ipWingLines = stack.getProcessor(3); ImagePlus impWingLines = new ImagePlus(nameEdited+" - frontiers",ipWingLines); IJ.run(impWingLines, "Gaussian Blur...", "sigma=1"); IJ.run(impWingLines, "Make Binary", ""); IJ.run(impWingLines, "Outline", ""); for(int lining = 1; lining < nrEyes; lining++){ //interval between each eyespot double dx = eyesCoord[lining][0]-eyesCoord[lining-1][0]; double dy = eyesCoord[lining][1]-eyesCoord[lining-1][1]; int n = (int)Math.round(distance(eyesCoord[lining-1][0], eyesCoord[lining-1][1], eyesCoord[lining][0], eyesCoord[lining][1])); double xFind = eyesCoord[lining-1][0]; double yFind = eyesCoord[lining-1][1]; int twoSides = 0; int direction = (int)Math.round(7*(double)(n)/8); double[] distFrontier = new double[3]; //0-> distance between frontiers | 1,2-> distance between frontier and point int[][] coordsFrontier = new int[2][2]; //coordinates for the two frontiers for each interval while(twoSides < 2){ //analysis for each point double xIncr = (1-2*twoSides)*(dx/n); double yIncr = (1-2*twoSides)*(dy/n); xFind = eyesCoord[lining-1+twoSides][0]+(n/8)*xIncr; //starting from n/8 yFind = eyesCoord[lining-1+twoSides][1]+(n/8)*yIncr; //starting from n/8 int pointsCounter = 0; boolean noFrontier = true; while(noFrontier && pointsCounter < direction){ //find the frontier black/yellow if(ipWingLines.getPixel((int)(xFind+0.5), (int)(yFind+0.5)) == 255){ distFrontier[twoSides+1] = distance(eyesCoord[lining-1+twoSides][0], eyesCoord[lining-1+twoSides][1], xFind+0.5, yFind+0.5); coordsFrontier[twoSides][0] = (int)(xFind+0.5); coordsFrontier[twoSides][1] = (int)(yFind+0.5); noFrontier = false; } else{ xFind += xIncr; yFind += yIncr; pointsCounter++; } } if(!noFrontier && twoSides == 0){ direction = (int)Math.round(distance(eyesCoord[lining][0], eyesCoord[lining][1], coordsFrontier[twoSides][0], coordsFrontier[twoSides][1])); //point with previous found frontier twoSides++; } else if(noFrontier){ twoSides = 2; //make the crossing point the middle between the two eyespots

Page 76: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

14  

interPoint[lining-1][0] = (int)(eyesCoord[lining-1][0]+dx/2); interPoint[lining-1][1] = (int)(eyesCoord[lining-1][1]+dy/2); } else{ twoSides++; } } if(distFrontier[2] != 0){ //distance between each frontier distFrontier[0] = distance(coordsFrontier[0][0], coordsFrontier[0][1], coordsFrontier[1][0], coordsFrontier[1][1]); } if(interPoint[lining-1][0] == 0){ //record the interPoint using the distances ratio double ratio; if((nrEyes == 7 || nrEyes == 8) && imgTp == 2){ ratio = (lining < 5)? distFrontier[2]/(distFrontier[1]+distFrontier[2]) : 0.5; } else{ ratio = 0.5; } interPoint[lining-1][0] = (int)(((ratio*distFrontier[0])+distFrontier[1])*(dx/n)+0.5+eyesCoord[lining-1][0]); interPoint[lining-1][1] = (int)(((ratio*distFrontier[0])+distFrontier[1])*(dy/n)+0.5+eyesCoord[lining-1][1]); } //coordinates to create the dividing lines boolean fiveVertical = true; if((nrEyes == 7 || nrEyes == 8) && imgTp == 2){ if(lining < 3){ if(eyesCoord[4][1] != eyesCoord[lining-1][1]){ m[lining-1] = -((eyesCoord[4][0]-eyesCoord[lining-1][0])/(eyesCoord[4][1]-eyesCoord[lining-1][1])); fiveVertical = false; } } if(lining == 3){ if(eyesCoord[5][1] != eyesCoord[lining-1][1]){ m[lining-1] = -((eyesCoord[5][0]-eyesCoord[lining-1][0])/(eyesCoord[5][1]-eyesCoord[lining-1][1])); fiveVertical = false; } } if(lining == 4){ if(eyesCoord[6][1] != eyesCoord[lining-1][1]){ m[lining-1] = -((eyesCoord[6][0]-eyesCoord[lining-1][0])/(eyesCoord[6][1]-eyesCoord[lining-1][1])); fiveVertical = false; } } if(lining == 5){ if(eyesCoord[lining+1][1] != eyesCoord[lining][1]){ m[lining-1] = -((eyesCoord[lining+1][0]-eyesCoord[lining][0])/(eyesCoord[lining+1][1]-eyesCoord[lining][1])); fiveVertical = false; } } if(lining > 5){ if(eyesCoord[lining][1] != eyesCoord[lining-1][1]){

Page 77: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

15  

m[lining-1] = -((eyesCoord[lining][0]-eyesCoord[lining-1][0])/(eyesCoord[lining][1]-eyesCoord[lining-1][1])); fiveVertical = false; } } } else if(eyesCoord[lining][1] != eyesCoord[lining-1][1]){ m[lining-1] = -((eyesCoord[lining][0]-eyesCoord[lining-1][0])/(eyesCoord[lining][1]-eyesCoord[lining-1][1])); fiveVertical = false; } //draw lines if(!fiveVertical){ b[lining-1] = interPoint[lining-1][1]-m[lining-1]*interPoint[lining-1][0]; ipLines.setColor(255); ipLines.drawLine((int)(-b[lining-1]/m[lining-1]),0,(int)(((height-1)-b[lining-1])/m[lining-1]),height-1); } else{ ipLines.setColor(255); ipLines.drawLine(interPoint[lining-1][0],0,interPoint[lining-1][0],height-1); } } } } if(showLines){ //show image with the dividing lines impLines = new ImagePlus(nameEdited+" - dividing lines", ipLines); impLines.show(); if(100+width+30 <= dimWidth){ if(100+height+50 <= dimHeight){ impLines.getWindow().setLocation(100, 100); } else{ impLines.getWindow().setLocation(100, 0); } } else if(100+height+50 <= dimHeight){ impLines.getWindow().setLocation(0, 100); } else{ impLines.getWindow().setLocation(0, 0); } IJ.showMessage("Lines","Image with the dividing lines"); impLines.hide(); } // <<-------------------- analysis of each eyespot -------------------->> if(imgTp < 3){ //to analyse normal eyespots images ImageProcessor whiteAreas = new ByteProcessor(width, height); //all eyespots white area image ImagePlus impW = new ImagePlus(nameEdited+" - White Area", whiteAreas); whiteAreas.invertLut(); ImageProcessor blackAreas = new ByteProcessor(width, height); //all eyespots black area image ImagePlus impB = new ImagePlus(nameEdited+" - Black Area", blackAreas);

Page 78: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

16  

blackAreas.invertLut(); ImageProcessor yellowAreas = new ByteProcessor(width, height); //all eyespots yellow area image ImagePlus impY = new ImagePlus(nameEdited+" - Yellow Area", yellowAreas); yellowAreas.invertLut(); ResultsTable rtAreasTemp = new ResultsTable(); int[] whiteCoord = new int[2]; int[][] paintAreas = new int[nrEyes][6]; //arrays for data from the areas {Eyespot, White, Black, Yellow} double[][] area = new double[nrEyes][4]; double[][] minAxis = new double[nrEyes][4]; double[][] majAxis = new double[nrEyes][4]; double[][] axisAngle = new double[nrEyes][4]; double[][] xCentroid = new double[nrEyes][4]; double[][] yCentroid = new double[nrEyes][4]; double[][] roundNess = new double[nrEyes][4]; int options = ParticleAnalyzer.INCLUDE_HOLES; int measurements = AREA+CIRCULARITY+CENTROID+ELLIPSE; int minSize = 1; int maxSize = 9999999; ParticleAnalyzer paEyespot = new ParticleAnalyzer(options, measurements, rtAreasTemp, minSize, maxSize); ParticleAnalyzer paWhite = new ParticleAnalyzer(options, measurements, rtAreasTemp, minSize, maxSize); ParticleAnalyzer paBlack = new ParticleAnalyzer(options, measurements, rtAreasTemp, minSize, maxSize); ParticleAnalyzer paYellow = new ParticleAnalyzer(options, measurements, rtAreasTemp, minSize, maxSize); int eyespot = 1; while(eyespot <= nrEyes){ //analyse each eyespot FloodFiller ff = new FloodFiller(ipLines); int x = (int)Math.ceil((double)width/2); int y = (int)Math.ceil((double)height/2); if(imgTp == 0){ //framing the image --> for glued eyespots or for missing parts of the yellow area IJ.setForegroundColor(105,105,105); //eyespot exterior color ipLines.drawRect(0,0,width,height); //outer frame IJ.setForegroundColor(0, 0, 0); //black ipLines.drawRect(1,1,width-2,height-2); //inner frame } else{ x = (int)eyesCoord[eyespot-1][0]; y = (int)eyesCoord[eyespot-1][1]; } ImageProcessor white = new ByteProcessor(width, height); //eyespot white area image ImagePlus impWhite = new ImagePlus(nameEdited+" - White Area", white); white.invertLut(); ImageProcessor black = new ByteProcessor(width, height); //eyespot black area image ImagePlus impBlack = new ImagePlus(nameEdited+" - Black Area", black); black.invertLut();

Page 79: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

17  

ImageProcessor yellow = new ByteProcessor(width, height); //eyespot yellow area image ImagePlus impYellow = new ImagePlus(nameEdited+" - Yellow Area", yellow); yellow.invertLut(); boolean whiteSearch = true; if(imgTp == 0) pixelLimit = 245; while(whiteSearch){ //find a white pixel near the center whiteCoord = findWhite(x,y,ip,pixelLimit); if(whiteCoord[0] == 0 || whiteCoord[1] == 0){ ip.sharpen(); } else{ whiteSearch = false; } } // <<-- find the frontiers of the different eyespot regions -->> int[] colors = {38,75,110,150,180,220,240}; //0 -> white | 180 -> debris color | 220 -> line color | 240 -> initial color | 255 -> black int borderCount = 1; x = whiteCoord[0]; y = whiteCoord[1]; int[] paintEyeAreas = {x,y,0,0,0,0}; paintAreas[eyespot-1] = paintEyeAreas; //coordinates for painting the areas int[] falseLine = {-1,-1}; ipLines.setColor(colors[borderCount-1]); ff.fill(x,y); //colorize the centre int[][] paintLinesBlack = new int[3][2]; //coordinates for painting the lines while (x <= width-1 && borderCount <= 3){ //<main> find frontiers loop (3x) if (ipLines.getPixel(x,y) == 255){ //black pixel (probably a frontier) found boolean notWritten = false; boolean hasWhitePixel = false; boolean notFound = true; int findWhiteX = x + 1; while(notFound && borderCount <= 3 && ipLines.getPixel(findWhiteX-1,y) == 255){ if(ipLines.getPixel(findWhiteX,y) == 0){ notFound = false; hasWhitePixel = true; } else if(ipLines.getPixel(findWhiteX,y) != 255){ notFound = false; } else{ findWhiteX++; } }

Page 80: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

18  

if(hasWhitePixel){ //frontier found if(!notWritten){ //to paint only once when it has to find the next black pixel ipLines.setColor(colors[borderCount]); ff.fill(findWhiteX,y); if(borderCount < 3){ paintAreas[eyespot-1][2*borderCount] = findWhiteX; //set the x coordinates for painting the areas at the end paintAreas[eyespot-1][2*borderCount+1] = y; //set the y coordinates for painting the areas at the end } if(borderCount > 1){ //paint previous frontier black ipLines.setColor(255); ff.fill8(paintLinesBlack[borderCount-2][0],paintLinesBlack[borderCount-2][1]); } } ImageProcessor ipTempW = new ByteProcessor(width, height); ImageProcessor ipTempB = new ByteProcessor(width, height); ImageProcessor ipTempY = new ByteProcessor(width, height); switch(borderCount){ //copy the imageprocessors to temporary ones case 1: ipTempW = white; ipTempB = black; break; case 2: ipTempB = black; ipTempY = yellow; break; case 3: ipTempY = yellow; break; } int initX = x; int initY = y; for(int i = -1; i < 2; i++){ //color the lower black pixels with debris color if(ipLines.getPixel(initX+i, initY+1) == 255){ ipLines.putPixel(initX+i, initY+1, colors[4]); } } int pixCounter = 1; //mark the 1st, 2nd, 3rd and 4th runFrontier loop notWritten = true; //nothing was written on the imageprocessor int passY = 0; boolean runFrontier = true; boolean colorize = true; while(runFrontier){ //running on the frontier

Page 81: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

19  

if(pixCounter == 2 && colorize){ //color the lower colored pixels to black color for(int i = -1; i < 2; i++){ if(ipLines.getPixel(initX+i, initY+1) == colors[4]){ ipLines.putPixel(initX+i, initY+1, 255); } } ipLines.putPixel(initX,initY,colors[6]); //color the initial pixel with initial color } if(pixCounter == 4 && falseLine[0] != -1){ //color the line of the possible hole black ipLines.setColor(colors[4]); ff.fill8(falseLine[0],falseLine[1]); ipLines.setColor(255); ff.fill8(falseLine[0],falseLine[1]); falseLine[0] = -1; falseLine[1] = -1; } // <<-- scan neighbors and find and select the next one -->> int[] viablePix = {0,0,0,0,0,0,0,0,0}; int[] nrColorIn = {0,0,0,0,0,0,0,0,0}; int[] nrColorLine = {0,0,0,0,0,0,0,0,0}; int neighborNr = -1; for(int i = -1; i < 2; i++){ //scan the y for(int j = -1; j < 2; j++){ //scan the x neighborNr++; int weightColorWhite = 0; //weight for white color if(ipLines.getPixel(x+j,y+i) == 255){ //if it's a black pixel neighbor int[] subPixBox = {ipLines.getPixel(x+j-1,y+i-1), ipLines.getPixel(x+j,y+i-1), ipLines.getPixel(x+j+1,y+i-1), ipLines.getPixel(x+j-1,y+i), ipLines.getPixel(x+j,y+i), ipLines.getPixel(x+j+1,y+i),

ipLines.getPixel(x+j-1,y+i+1), ipLines.getPixel(x+j,y+i+1), ipLines.getPixel(x+j+1,y+i+1)};

int weightColorIn = 0; //weight for inner color int weightColorOut = 0; //weight for outer color for(int neighbor = 0; neighbor < 9; neighbor++){ //analysis of neighbor pixels if(subPixBox[neighbor] == colors[borderCount-1]){ nrColorIn[neighborNr]++; } if(subPixBox[neighbor] == colors[5]){ nrColorLine[neighborNr]++; } if(subPixBox[neighbor] == colors[borderCount-1] && weightColorIn == 0){ weightColorIn++; } if(subPixBox[neighbor] == colors[borderCount] && weightColorOut == 0){ weightColorOut++; }

Page 82: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

20  

} if(weightColorIn + weightColorOut == 2){ viablePix[neighborNr] = 1; //it's a viable black - to be colored with line color } else{ viablePix[neighborNr] = 2 //it's a non viable black - it will be colored with debris color } } else if(ipLines.getPixel(x+j,y+i) == colors[6]){ viablePix[neighborNr] = -1; //it's the initial color pixel } else if(ipLines.getPixel(x+j,y+i) == 0){ viablePix[neighborNr] = -2; //it's a white pixel } else{ viablePix[neighborNr] = 0; //it's not black, white or initial color } } } //eliminates the xy pixel from the neighbor analysis if(pixCounter == 1) viablePix[4] = 0; nrColorIn[4] = 0; nrColorLine[4] = 0; //get the smallest nrColorIn int minColorIn = 0; for(int preRun = 8; preRun >= 0; preRun--){ if(nrColorIn[preRun] != 0 && viablePix[preRun] > 0) minColorIn = preRun; } for(int run = 0; run < 9; run++){ if(nrColorIn[run] < nrColorIn[minColorIn] && nrColorIn[run] != 0 && viablePix[run] == 1)

minColorIn = run; } //get the smallest nrColorLine int minColorLine = 0; for(int preRun = 8; preRun >= 0; preRun--){ if(nrColorLine[preRun] != 0 && viablePix[preRun] == 1) minColorLine = preRun; } for(int line = 0; line < 9; line++){ if(nrColorLine[line] < nrColorLine[minColorLine] && nrColorLine[line] != 0 && viablePix[line] == 1) minColorLine = line; } int whiteCounter = 0; for(int w = 0; w < 9; w++) if(viablePix[w] == -2) whiteCounter++; //count the white neighbor pixels int oneCount = 0; for(int a = 0; a < 9; a++) if(viablePix[a] == 1) oneCount++; //count the viable black pixels boolean initialPixel = false; int initialFound = 0;

Page 83: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

21  

while(initialFound < 9){ //to find if one of the neighbors is the initial pixel if(viablePix[initialFound] == -1){ initialPixel = true; initialFound = 9; } else{ initialFound++; } } //find next pixel to analyse int newCoord = 4; if(initialPixel && pixCounter == 4){ //found the initial colored pixel -> end of frontier int iniPixel = -1; for(int j = 6; j > -1; j = j - 3){ for(int i = 0; i < 3; i++){ if(viablePix[i + j] == -1) iniPixel = i + j; } } newCoord = iniPixel; //set the new coordinates of xy } else if(oneCount == 0 && !notWritten){ //floodfill all white pixel neighbors with exterior color if(whiteCounter != 0){ for(int whitePix = 0; whitePix < 9; whitePix++){ if(viablePix[whitePix] == -2){ int a; int b; if(whitePix%3 == 0){ a = x - 1; } else if((whitePix - 2)%3 == 0){ a = x + 1; } else{ a = x; } if(whitePix < 3){ b = y - 1; } else if(whitePix > 5){ b = y + 1; } else{ b = y; } ipLines.setColor(colors[borderCount]); ff.fill(a,b); } } colorize = false; //to analyse the neighbors again for(int v = -1; v < 2; v++){ //convert every debris pixel around xy to black for(int w = -1; w < 2; w++){ if(ipLines.getPixel(x+v,y+w) == colors[4]){

Page 84: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

22  

ipLines.putPixel(x+v,y+w,255); } } } } else{ newCoord = minColorIn; colorize = true; } } else if(oneCount == 1){ //found the next pixel int one = 0; while(one < 9){ if(viablePix[one] == 1){ newCoord = one; //set the new coordinates of xy notWritten = false; colorize = true; one = 9; } else{ one++; } } } else if(oneCount == 2 && !notWritten){ //found 2 possible next pixel next to each other if(viablePix[2] == 1 || viablePix[6] == 1){ //choosing the diagonal one for(int a = 2; a < 7; a= a+4){ if(viablePix[a] == 1){ if(viablePix[a/2] == 1 || viablePix[(a/2)+4] == 1){ newCoord = a; //set the new coordinates of xy } else{ newCoord = minColorLine; } } } } else if(viablePix[0] == 1 || viablePix[8] == 1){ //choosing the diagonal one for(int b = 1; b < 6; b = b+4){ if(viablePix[2*(b-1)] == 1){ if(viablePix[b] == 1 || viablePix[b+2] == 1){ newCoord = 2*(b-1); //set the new coordinates of xy } else{ newCoord = minColorLine; } } } }else{ //no black pixel in any diagonal for(int c = 0; c < 9; c++){ if(viablePix[c] == 1 && c != minColorIn){ newCoord = c; } } } colorize = true;

Page 85: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

23  

} else if(oneCount == 2 || oneCount == 3){ //several possible next pixels on the first line pixel int twoOne = 0; while(twoOne < 3){ if(viablePix[twoOne] == 1){ newCoord = twoOne; //set the new coordinates of xy notWritten = false; colorize = true; twoOne = 3; } else{ twoOne++; } } } else if(oneCount == 0){ //found the frontier pixel too much inside the inner area x = x + 1; //move forward on the line until it gets to the frontier for(int i = -1; i < 2; i++){ //color the lower colored pixels back to black, if any if(ipLines.getPixel(initX+i, initY+1) == colors[4]){ ipLines.putPixel(initX+i, initY+1, 255); } } ipLines.putPixel(findWhiteX,y,0); colorize = false; runFrontier = false; //to make the program start the <main> again } else{ //error print out IJ.showMessage("Error","An error occurred at pixel x,y = ("+x+", "+y+")\n

\nCouldn't find the next pixel."); return; } //sets the color for black pixels to debris color int debrisPixel = 0; while(debrisPixel <= 8 && colorize){ if(viablePix[debrisPixel] == 2 || viablePix[debrisPixel] == 1){ int a; int b; if(debrisPixel%3 == 0){ a = x - 1; } else if((debrisPixel - 2)%3 == 0){ a = x + 1; } else{ a = x; } if(debrisPixel < 3){ b = y - 1; } else if(debrisPixel > 5){ b = y + 1; } else{ b = y; }

Page 86: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

24  

ipLines.putPixel(a,b,colors[4]); debrisPixel++; } else{ debrisPixel++; } } //sets the coordinates for the next pixel if(colorize){ if(newCoord%3 == 0){ x = x - 1; } else if((newCoord - 2)%3 == 0){ x = x + 1; } if(newCoord < 3){ y = y - 1; } else if(newCoord > 5){ y = y + 1; } } //put the frontier pixel in the temporary imageprocessors if(colorize){ switch(borderCount){ case 1: ipTempW.putPixel(x,y,255); ipTempB.putPixel(x,y,255); break; case 2: ipTempB.putPixel(x,y,255); ipTempY.putPixel(x,y,255); break; case 3: ipTempY.putPixel(x,y,255); break; } notWritten = false; } if(y == initY && passY == 0 && !notWritten && colorize){ //passing the first (top) half of the frontier passY = 1; if(x > initX){ //find if the opposite-x pixel of initY+1 is on the wrong side runFrontier = false; ipLines.putPixel(x,y,255); //colorize final pixel with black ipLines.putPixel(initX,initY,colors[5]); //colorize initial pixel to line color falseLine[0] = initX; falseLine[1] = initY; int altX = x - 1; boolean isNotFound = true;

Page 87: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

25  

while(isNotFound){ if(ipLines.getPixel(altX,y) == colors[borderCount]){ ipLines.setColor(0); ff.fill(altX,y); //fill possible hole with white isNotFound = false; } else{ altX--; } } } } else if(ipLines.getPixel(x,y) == colors[6] && colorize){ //if xy is a pixel with initial color – the frontier is complete runFrontier = false; ipLines.putPixel(x,y,colors[5]); //paint the initial pixel with line color ipLines.setColor(colors[4]); ff.fill8(x,y); //floodfill with debris color paintLinesBlack[borderCount-1][0] = x; paintLinesBlack[borderCount-1][1] = y; switch(borderCount){ //put the temporary imageprocessor to the original one case 1: white = ipTempW; black = ipTempB; break; case 2: black = ipTempB; yellow = ipTempY; break; case 3: yellow = ipTempY; ipLines.setColor(255); ff.fill8(paintLinesBlack[borderCount-1][0],paintLinesBlack[borderCount-1][1]); //paint last frontier (and the dividing lines) black break; } borderCount++; } if(pixCounter < 4 && !notWritten && colorize) pixCounter++; //mark the first 4 loops/pixels if(runFrontier && !notWritten && colorize) ipLines.putPixel(x,y,colors[5]); //paint the next xy pixel with line color } } else{ //go search for frontier again after the false black pixel x = findWhiteX; } } else{ //walks to the right x++; } }//end of <main> find frontiers loop

Page 88: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

26  

//reset the black, yellow and external area to white ipLines.setColor(colors[1]); //black area color ff.fill8(paintAreas[eyespot-1][0],paintAreas[eyespot-1][1]); //paint white area ipLines.setColor(colors[2]); //yellow area color ff.fill8(paintAreas[eyespot-1][2],paintAreas[eyespot-1][3]); //paint black area and white area ipLines.setColor(colors[3]); //external area color ff.fill8(paintAreas[eyespot-1][2],paintAreas[eyespot-1][3]); //paint all 3 areas ipLines.setColor(0); //white ff.fill8(paintAreas[eyespot-1][2],paintAreas[eyespot-1][3]); //paint all 3 areas and exterior //fill the areas on each isolated area image FloodFiller fW = new FloodFiller(white); FloodFiller fB = new FloodFiller(black); FloodFiller fY = new FloodFiller(yellow); white.setColor(255); black.setColor(255); yellow.setColor(255); fW.fill(paintAreas[eyespot-1][0],paintAreas[eyespot-1][1]); fB.fill(paintAreas[eyespot-1][2],paintAreas[eyespot-1][3]); fY.fill(paintAreas[eyespot-1][4],paintAreas[eyespot-1][5]); //Add each area to the images with all the eyespots ImageCalculator icMerge = new ImageCalculator(); ImagePlus impAreas = icMerge.run("OR create", impW, impWhite); impW.setProcessor(impAreas.getProcessor()); impAreas = icMerge.run("OR create", impB, impBlack); impB.setProcessor(impAreas.getProcessor()); impAreas = icMerge.run("OR create", impY, impYellow); impY.setProcessor(impAreas.getProcessor()); //get data from the areas impYellow.copyScale(imp); paEyespot.analyze(impYellow, yellow); //Analyse eyespot impWhite.copyScale(imp); paWhite.analyze(impWhite, white); //Analyse white impBlack.copyScale(imp); paBlack.analyze(impBlack, black); //Analyse black paYellow.analyze(impYellow, yellow); //Analyse yellow area[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.AREA); minAxis[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.MINOR); majAxis[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.MAJOR); axisAngle[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.ANGLE); xCentroid[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.X_CENTROID); yCentroid[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.Y_CENTROID); roundNess[eyespot-1] = rtAreasTemp.getColumnAsDoubles(ResultsTable.ROUNDNESS); area[eyespot-1][3] = area[eyespot-1][3] - area[eyespot-1][2]; area[eyespot-1][2] = area[eyespot-1][2] - area[eyespot-1][1];

Page 89: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

27  

rtAreasTemp.reset(); eyespot++; }//end of analysis of all the eyespots // <<-- shows individual pictures for each area -->> if(showAreas){ int side = 0; int space = 30; if (3*(width+30) <= dimWidth-200){ space = (dimWidth-200-3*(width+30))/2; side = 100; } else if(3*(width+30) <= dimWidth-100){ space = (dimWidth-100-3*(width+30))/2; side = 50; } else{ side = (dimWidth-width-30/2)-width-30; } impW.show(); if(100+height+50 <= dimHeight){ impW.getWindow().setLocation(side, dimHeight-(60+height+50)); } else{ impW.getWindow().setLocation(side, 0); } impB.show(); if(100+height+50 <= dimHeight){ impB.getWindow().setLocation(side+width+30+space, dimHeight-(60+height+50)); } else{ impB.getWindow().setLocation(side+width+30+space, 0); } impY.show(); if(100+height+50 <= dimHeight){ impY.getWindow().setLocation(side+2*(width+30+space), dimHeight-(60+height+50)); } else{ impY.getWindow().setLocation(side+2*(width+30+space), 0); } IJ.showMessage("Areas","Images for each area"); impW.hide(); impB.hide(); impY.hide(); } // <<-- put the chosen data in the ResultsTable -->> String[] sufixEye = new String[listener]; //array with the names for each normal eyespot if(nrEyes == listener){

Page 90: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

28  

switch(imgTp){ case 1: sufixEye[0] = "A - "; sufixEye[1] = "P - "; break; case 2: for(int hS = 1; hS <= listener; hS++) sufixEye[hS-1] = "h"+hS+" - "; break; default: sufixEye[0] = ""; } } else{ for(int fx = 1; fx <= nrEyes; fx++) sufixEye[fx] = ""+fx+" - "; } //get the numbers of the eyespots to be analysed int analyseL = (analyse.length()+1)/2; if(analyse.equalsIgnoreCase("all")) analyseL = nrEyes; int[] analyseEyes = new int[analyseL]; if(!(analyse.equalsIgnoreCase("all"))){ for(int numbers = 0; numbers < analyse.length(); numbers=numbers+2) analyseEyes[numbers/2] = analyse.charAt(numbers)-48; } else{ for(int nrFill = 0; nrFill < nrEyes; nrFill++) analyseEyes[nrFill] = nrFill+1; } Arrays.sort(analyseEyes); if(images == 1){ for(int loop = 0; loop < areasCount*analyseL*nrImages; loop++) //increase the counter of the resultsTable rtAreas.incrementCounter(); } for(int eyespots = 0; eyespots < analyseL; eyespots++){ //put the measurements int line = nrEyes*areasCount*(images-1)+eyespots*areasCount; for(int sel = 0; sel < selectedAreas.length; sel++){ if(selectedAreas[sel]){ rtAreas.setLabel(nameEdited+" - "+sufixEye[analyseEyes[eyespots]-1]+labelsAreas[sel]+" area",line); if(showArea) rtAreas.setValue("Area", line, area[analyseEyes[eyespots]-1][sel]/(scale*scale*size*size)); if(showRoundness) rtAreas.setValue("Roundness", line, roundNess[analyseEyes[eyespots]-1][sel]); if(showDiameters){ rtAreas.setValue("MinorAxis", line, minAxis[analyseEyes[eyespots]-1][sel]/(scale*size)); rtAreas.setValue("MajorAxis", line, majAxis[analyseEyes[eyespots]-1][sel]/(scale*size)); if(sel > 1){ rtAreas.setValue("MinorWidth", line, (minAxis[analyseEyes[eyespots]-1][sel]-

minAxis[analyseEyes[eyespots]-1][sel-1])/(2*scale*size)); rtAreas.setValue("MajorWidth", line, (majAxis[analyseEyes[eyespots]-1][sel]-

majAxis[analyseEyes[eyespots]-1][sel-1])/(2*scale*size));

Page 91: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

29  

} } line++; } } line = nrEyes*areasCount*(images-1)+eyespots*areasCount; if(ratiosNr != 0){ //put the areas ratios if(ratios[0]) for(int eye = 1; eye < selectedAreas.length; eye++) if(ratios[eye]) rtAreas.setValue(labelsAreas[eye]+"Area/SpotArea", line,

(area[analyseEyes[eyespots]-1][eye]/area[analyseEyes[eyespots]-1][0])); if(ratios[1]) for(int wt = 2; wt < selectedAreas.length; wt++) if(ratios[wt]) rtAreas.setValue("WhiteArea/"+labelsAreas[wt]+"Area", line,

(area[analyseEyes[eyespots]-1][1]/area[analyseEyes[eyespots]-1][wt])); if(ratios[2]) rtAreas.setValue("YellowArea/BlackArea", line,

(area[analyseEyes[eyespots]-1][3]/area[analyseEyes[eyespots]-1][2])); } } // <<-- depictions of the eyespots -->> //int[][] colorPalette = {{250,250,250},{0,0,0},{255,255,0},{185,111,0}}; int[] paletteDec = {16448250,0,16776960,12152576}; //colours: {250,250,250}, {0,0,0}, {255,255,0}, {185,111,0} int pics = 0; if(drawOriginal){ //drawing the colored original areas ImageProcessor yellowC = (impY.getProcessor()).convertToRGB(); FloodFiller ffY = new FloodFiller(yellowC); yellowC.setColor(paletteDec[2]); for(int yllw = 0; yllw < nrEyes; yllw++) ffY.fill(paintAreas[yllw][4],paintAreas[yllw][5]); ImagePlus impYellowC = new ImagePlus("yellow", yellowC); ImagePlus impBlackC = new ImagePlus("black", (impB.getProcessor()).convertToRGB()); ImageCalculator ic = new ImageCalculator(); ImagePlus impColored = ic.run("AND create", impYellowC, impBlackC); ImageProcessor ipColored = impColored.getProcessor(); FloodFiller ffColored = new FloodFiller(ipColored); ipColored.setColor(paletteDec[3]); int xOut = paintAreas[0][4]; while(xOut < width){ if(ipColored.getPixelValue(xOut, paintAreas[0][5]) == 255){ ffColored.fill(xOut,paintAreas[0][5]); xOut = width;

Page 92: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

30  

} else{ xOut++; } } impColored.setTitle(nameEdited+" - colored original areas"); impColored.show(); if(nrImages== 1){ //set location of image if(100+width+30 >= dimWidth || 50+height+50 >= dimHeight) IJ.run("Out [-]", ""); impColored.getWindow().setLocation(dimWidth-(100+width+30), 50); pics = 50+height+50; } } if(drawEllipses){ //drawing the colored elliptical areas ImageProcessor ipEllTempOne = new ColorProcessor(width, height); ImagePlus impEllTempOne = new ImagePlus("tempOne", ipEllTempOne); impEllTempOne.copyScale(imp); ipEllTempOne.invert(); ImageProcessor ipEllTempTwo = new ColorProcessor(width, height); ImagePlus impEllTempTwo = new ImagePlus("tempTwo", ipEllTempTwo); impEllTempTwo.copyScale(imp); ipEllTempTwo.invert(); ImageProcessor ipEllY = new ColorProcessor(width, height); ImagePlus impEllY = new ImagePlus("Yellow ellipses", ipEllY); impEllY.copyScale(imp); ipEllY.invert(); ImageProcessor ipEllB = new ColorProcessor(width, height); ImagePlus impEllB = new ImagePlus("Black ellipses", ipEllB); impEllB.copyScale(imp); ipEllB.invert(); ImageCalculator icA = new ImageCalculator(); //yellow and black ellipses for(int eyespots = 0; eyespots < nrEyes; eyespots++){ //yellow ellipses ipEllTempOne.setColor(paletteDec[2]); ipEllTempOne.fillOval((int)(xCentroid[eyespots][3]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][3]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroid[eyespots][3]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxis[eyespots][3]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxis[eyespots][3]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxis[eyespots][3]/((imp.getCalibration()).pixelWidth))); ipEllTempOne.setRoi((int)Math.round(xCentroid[eyespots][3]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][3]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(yCentroid[eyespots][3]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][3]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(majAxis[eyespots][3]/((imp.getCalibration()).pixelWidth)) + 2, (int)Math.round(majAxis[eyespots][3]/((imp.getCalibration()).pixelWidth)) + 2);

Page 93: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

31  

ipEllTempOne.rotate(-axisAngle[eyespots][3]); ImagePlus impTempOne = icA.run("AND create", impEllY, impEllTempOne); impEllY.setProcessor("Yellow ellipses", impTempOne.getProcessor()); ipEllTempOne.setColor(16777215); ipEllTempOne.fill(); //black ellipses ipEllTempTwo.setColor(paletteDec[1]); ipEllTempTwo.fillOval((int)Math.round(xCentroid[eyespots][2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroid[eyespots][2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxis[eyespots][2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxis[eyespots][2]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxis[eyespots][2]/((imp.getCalibration()).pixelWidth))); ipEllTempTwo.setRoi((int)Math.round(xCentroid[eyespots][2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][2]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(yCentroid[eyespots][2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][2]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(majAxis[eyespots][2]/((imp.getCalibration()).pixelWidth)) + 2, (int)Math.round(majAxis[eyespots][2]/((imp.getCalibration()).pixelWidth)) + 2); ipEllTempTwo.rotate(-axisAngle[eyespots][2]); ImagePlus impTempTwo = icA.run("AND create", impEllB, impEllTempTwo); impEllB.setProcessor("Black ellipses", impTempTwo.getProcessor()); ipEllTempTwo.setColor(16777215); ipEllTempTwo.fill(); } FloodFiller fYl = new FloodFiller(impEllY.getProcessor()); (impEllY.getProcessor()).setColor(paletteDec[3]); //brown background fYl.fill(0, 0); ImageCalculator icI = new ImageCalculator(); ImagePlus impEllTempThree = icI.run("AND create", impEllY, impEllB); (impEllY.getProcessor()).setColor(0); (impEllY.getProcessor()).fill(); ipEllTempOne.setColor(0); ipEllTempOne.fill(); //white ellipses for(int eyespots = 0; eyespots < nrEyes; eyespots++){ ipEllTempOne.setColor(paletteDec[0]); ipEllTempOne.fillOval((int)Math.round(xCentroid[eyespots][1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroid[eyespots][1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxis[eyespots][1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxis[eyespots][1]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxis[eyespots][1]/((imp.getCalibration()).pixelWidth))); ipEllTempOne.setRoi((int)Math.round(xCentroid[eyespots][1]/((imp.getCalibration()).pixelWidth)) –

Page 94: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

32  

(int)Math.round(majAxis[eyespots][1]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(yCentroid[eyespots][1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxis[eyespots][1]/(2*((imp.getCalibration()).pixelWidth))) - 1, (int)Math.round(majAxis[eyespots][1]/((imp.getCalibration()).pixelWidth)) + 2, (int)Math.round(majAxis[eyespots][1]/((imp.getCalibration()).pixelWidth)) + 2); ipEllTempOne.rotate(-axisAngle[eyespots][1]); ImagePlus impTempThree = icA.run("OR create", impEllY, impEllTempOne); impEllY.setProcessor("White ellipses", impTempThree.getProcessor()); ipEllTempOne.setColor(0); ipEllTempOne.fill(); } ImageCalculator icII = new ImageCalculator(); ImagePlus impColored = icII.run("OR create", impEllTempThree, impEllY); impColored.setTitle(nameEdited+" - colored elliptical areas"); impColored.show(); if(nrImages== 1){ //set location of image if(100+width+30 >= dimWidth || 50+height+50 >= dimHeight) IJ.run("Out [-]", ""); if(pics+50+height+50 >= dimHeight){ impColored.getWindow().setLocation(100, 50); } else{ impColored.getWindow().setLocation(dimWidth-(100+width+30), 50+pics); } } } } else{ //to analyse gene expression images ResultsTable rtPoints = new ResultsTable(); int measurements = AREA+CIRCULARITY+CENTROID+ELLIPSE; ParticleAnalyzer paPoints = new ParticleAnalyzer(ParticleAnalyzer.INCLUDE_HOLES, measurements, rtPoints, 1, 9999999); Duplicator duplicate = new Duplicator(); ImagePlus impPointsAll = duplicate.run(imp); //whole eyespot IJ.run(impPointsAll, "Maximum...", "radius=5"); IJ.run(impPointsAll, "Gaussian Blur...", "sigma=5"); IJ.run(impPointsAll, "Make Binary", ""); ImagePlus impPointsCentre = duplicate.run(imp); //centre area IJ.run(impPointsCentre, "Make Binary", ""); IJ.run(impPointsCentre, "Close-", ""); IJ.run(impPointsCentre, "Erode", ""); ImagePlus impPointsIn = duplicate.run(imp); //intermediate frontier IJ.run(impPointsIn, "Maximum...", "radius=5"); IJ.run(impPointsIn, "Gaussian Blur...", "sigma=5"); IJ.run(impPointsIn, "Make Binary", ""); IJ.run(impPointsIn, "Outline", ""); ImagePlus impSlices = duplicate.run(imp); //smoothed image to obtain cross sections for analysis IJ.run(impSlices, "HSB Stack", ""); ImageStack stack = impSlices.getStack();

Page 95: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

33  

ImageProcessor ipPoints = stack.getProcessor(3); ImagePlus impPoints = new ImagePlus(nameEdited+" - blured areas",ipPoints); IJ.run(impPoints, "Maximum...", "radius=5"); IJ.run(impPoints, "Gaussian Blur...", "sigma=5"); int erosions = 1; paPoints.analyze(impPointsCentre, impPointsCentre.getProcessor()); while(rtPoints.getCounter() > 1){ //get only the centre area rtPoints.reset(); IJ.run(impPointsCentre, "Erode", ""); paPoints.analyze(impPointsCentre, impPointsCentre.getProcessor()); erosions++; } rtPoints.reset(); for(int dil = 0; dil < erosions; dil++) IJ.run(impPointsCentre, "Dilate", ""); //revert back the size of the centre ImageProcessor ipPointsIn = impPointsIn.getProcessor(); if(imgTp == 4){ FloodFiller fLine = new FloodFiller(ipPointsIn); ipPointsIn.setColor(0); int xx = 0; boolean noLine = true; while(noLine){ //clear the outer most outline if(ipPointsIn.getPixel(xx,(int)Math.ceil(height/2)) == 255){ fLine.fill(xx,(int)Math.ceil(height/2)); noLine = false; } else{ xx++; } } } paPoints.analyze(impPointsCentre, impPointsCentre.getProcessor()); //get data from the centre area if(imgTp == 4){ paPoints.analyze(impPointsIn, ipPointsIn); //get data from the intermediate frontier int maxPos = rtPoints.getCounter()-1; for(int i = rtPoints.getCounter()-2; i >= 1; i--){ //remove the smallest areas if(rtPoints.getValue("Area", i) > rtPoints.getValue("Area", maxPos)){ rtPoints.deleteRow(maxPos); } else{ rtPoints.deleteRow(i); } maxPos = i; } } paPoints.analyze(impPointsAll, impPointsAll.getProcessor()); //get data from the whole area int maxPos = rtPoints.getCounter()-1; for(int i = rtPoints.getCounter()-2; i >= imgTp-2; i--){ //remove the smallest areas if(rtPoints.getValue("Area", i) > rtPoints.getValue("Area", maxPos)){

Page 96: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

34  

rtPoints.deleteRow(maxPos); } else{ rtPoints.deleteRow(i); } maxPos = i; } double[] areaSpot = rtPoints.getColumnAsDoubles(ResultsTable.AREA); double[] minAxisSpot = rtPoints.getColumnAsDoubles(ResultsTable.MINOR); double[] majAxisSpot = rtPoints.getColumnAsDoubles(ResultsTable.MAJOR); double[] axisAngleSpot = rtPoints.getColumnAsDoubles(ResultsTable.ANGLE); double[] xCentroidSpot = rtPoints.getColumnAsDoubles(ResultsTable.X_CENTROID); double[] yCentroidSpot = rtPoints.getColumnAsDoubles(ResultsTable.Y_CENTROID); double[] roundnessSpot = rtPoints.getColumnAsDoubles(ResultsTable.ROUNDNESS); int lengthPts = rtPoints.getCounter(); rtPoints.reset(); if(lengthPts == 3) areaSpot[1] = areaSpot[2]-areaSpot[1]; if(images == 1) for(int loop = 0; loop < lengthPts*nrImages; loop++)

rtAreas.incrementCounter(); //increase the counter of the main resultsTable String[] labelsPoints = new String[lengthPts]; switch(lengthPts){ case 2: labelsPoints[0] = "Centre"; labelsPoints[1] = "Whole"; break; case 3: labelsPoints[0] = "Centre"; labelsPoints[1] = "Band"; labelsPoints[2] = "Whole"; break; } for(int sel = 0; sel < lengthPts; sel++){ //put the measurements rtAreas.setLabel(nameEdited+" - "+labelsPoints[sel]+" area",point); if(showArea) rtAreas.setValue("Area", point, areaSpot[sel]/(scale*scale)); if(showRoundness) rtAreas.setValue("Roundness", point, roundnessSpot[sel]); if(showDiameters){ rtAreas.setValue("MinorAxis", point, minAxisSpot[sel]/scale); rtAreas.setValue("MajorAxis", point, majAxisSpot[sel]/scale); } point++; } if(avgCutSection || widCutSection || shrCutSection){ //get the cross sections int extraW = (int)(Math.ceil(xCentroidSpot[0]/((imp.getCalibration()).pixelWidth))-(width-1)/2);

Page 97: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

35  

int extraH = (int)(Math.ceil(yCentroidSpot[0]/((imp.getCalibration()).pixelWidth))-(height-1)/2); int diagonalPts = (int)distance(0,0,width-1,height-1); ImageProcessor ipPointsRt = ipPoints.createProcessor(diagonalPts+2*Math.abs(extraW), diagonalPts+2*Math.abs(extraH)); ipPointsRt.setBackgroundValue(0); ipPointsRt.fill(); ImagePlus impPointsRt = new ImagePlus(nameEdited, ipPointsRt); int widthRt = impPointsRt.getWidth(); int heightRt = impPointsRt.getHeight(); ipPointsRt.insert(ipPoints, (int)Math.round((double)(widthRt-width)/2)-1*extraW,

(int)Math.round((double)(heightRt-height)/2)-1*extraH); int angle = 0; if(avgCutSection){ //average cross section ImageProcessor ipRtOne = new ByteProcessor(widthRt, heightRt); ImagePlus impRtOne = new ImagePlus("one", ipRtOne); ImageProcessor ipRtTwo = new ByteProcessor(widthRt, heightRt); ImagePlus impRtTwo = new ImagePlus("two", ipRtTwo); ImageProcessor ipRtThree = new ByteProcessor(widthRt, heightRt); ImagePlus impRtThree = new ImagePlus("three", ipRtThree); ImageProcessor ipNumberThree = new ByteProcessor(widthRt, heightRt); ImagePlus impNumberThree = new ImagePlus("number", ipNumberThree); ImageProcessor ipNumberTwo = new ByteProcessor(widthRt, heightRt); ImagePlus impNumberTwo = new ImagePlus("number", ipNumberTwo); ImageProcessor ipNumberOne = new ByteProcessor(widthRt, heightRt); ipNumberOne.setColor(1); ipNumberOne.fill(); ImagePlus impNumberOne = new ImagePlus("number", ipNumberOne); ImageCalculator icRt = new ImageCalculator(); impRtOne = impPointsRt; angle = 45; ipPointsRt.rotate(angle); impRtTwo = icRt.run("Average create", impRtOne, impPointsRt); int nrLayers = 360/angle; for(int angles = 2; angles < nrLayers; angles++){ ipPointsRt.rotate(angle); ipNumberTwo.setColor(angles); ipNumberTwo.fill(); ipNumberThree.setColor(angles+1); ipNumberThree.fill(); impRtOne = icRt.run("Divide create", impRtTwo, impNumberThree); //previous average/(n+1) impRtThree = icRt.run("Multiply create", impRtOne, impNumberTwo); //n*previous average/(n+1) impRtOne = icRt.run("Divide create", impPointsRt, impNumberThree); //new rotated image/(n+1) impRtTwo = icRt.run("Add create", impRtThree, impRtOne); //n*prev average/(n+1) + new/(n+1) impRtTwo.setTitle(nameEdited+" - average cross section"); }

Page 98: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

36  

impRtTwo.setRoi((int)Math.round((double)Math.ceil(widthRt/2)- 5*majAxisSpot[lengthPts-1]/(8*((imp.getCalibration()).pixelWidth))), (int)Math.round((double)Math.ceil(heightRt/2)-majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(5*majAxisSpot[lengthPts-1]/(4*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth))); //roi selection

impRtTwo.copyScale(imp); ProfilePlot ppAvg = new ProfilePlot(impRtTwo); //profile plot ppAvg.setMinAndMax(0,255); ppAvg.createWindow(); if(nrImages == 1){ if((widCutSection && !shrCutSection) || (!widCutSection && shrCutSection)){ WindowManager.getCurrentWindow().setLocation(30, dimHeight-338-50); } if(!widCutSection && !shrCutSection){ WindowManager.getCurrentWindow().setLocation((dimWidth-553)/2, dimHeight-338-50); } } } if(widCutSection){ impPointsRt.setTitle(nameEdited+" - widest cross section"); ipPointsRt.rotate(angle+axisAngleSpot[lengthPts-1]); impPointsRt.setRoi((int)Math.round((double)Math.ceil(widthRt/2)-

5*majAxisSpot[lengthPts-1]/(8*((imp.getCalibration()).pixelWidth))), (int)Math.round((double)Math.ceil(heightRt/2)- majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(5*majAxisSpot[lengthPts-1]/(4*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth))); //roi selection

impPointsRt.copyScale(imp); ProfilePlot ppWid = new ProfilePlot(impPointsRt); //profile plot ppWid.setMinAndMax(0,255); ppWid.createWindow(); if(nrImages == 1){ if(avgCutSection && !shrCutSection){ WindowManager.getCurrentWindow().setLocation(30+553+30, dimHeight-338-50); } if(shrCutSection){ WindowManager.getCurrentWindow().setLocation(30, dimHeight-338-50); } if(!avgCutSection && !shrCutSection){ WindowManager.getCurrentWindow().setLocation((dimWidth-553)/2, dimHeight-338-50); } } } if(shrCutSection){ impPointsRt.setTitle(nameEdited+" - shortest cross section"); ipPointsRt.rotate(angle+axisAngleSpot[lengthPts-1]-90); impPointsRt.setRoi((int)Math.round((double)Math.ceil(widthRt/2)-

Page 99: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

37  

5*majAxisSpot[lengthPts-1]/(8*((imp.getCalibration()).pixelWidth))), (int)Math.round((double)Math.ceil(heightRt/2)- majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(5*majAxisSpot[lengthPts-1]/(4*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth))); //roi selection

impPointsRt.copyScale(imp); ProfilePlot ppWid = new ProfilePlot(impPointsRt); //profile plot ppWid.setMinAndMax(0,255); ppWid.createWindow(); if(nrImages == 1){ if(avgCutSection || widCutSection){ WindowManager.getCurrentWindow().setLocation(30+553+30, dimHeight-338-50); } else{ WindowManager.getCurrentWindow().setLocation((dimWidth-553)/2, dimHeight-338-50); } } } } if(drawEllipses){ //draw image with elliptises ImageProcessor ipEllTempOne = new ColorProcessor(width, height); ImagePlus impEllTempOne = new ImagePlus("tempOne", ipEllTempOne); ipEllTempOne.invert(); ImageProcessor ipEllTempTwo = new ColorProcessor(width, height); ImagePlus impEllTempTwo = new ImagePlus("tempTwo", ipEllTempTwo); ipEllTempTwo.invert(); ImagePlus impTempOne = new ImagePlus(); ImageCalculator icA = new ImageCalculator(); int[] palette = {16711680, 12125952, 1095936}; //dll centre | dll whole | en whole and centre ipEllTempOne.setColor(palette[imgTp-2]); ipEllTempOne.fillOval((int)Math.round(xCentroidSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxisSpot[lengthPts-1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxisSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth))); ipEllTempOne.setRoi((int)Math.round(xCentroidSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-1]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) + 1, (int)Math.round(majAxisSpot[lengthPts-1]/((imp.getCalibration()).pixelWidth)) + 1); ipEllTempOne.rotate(-axisAngleSpot[lengthPts-1]); ipEllTempOne.setColor(0); FloodFiller fEllO = new FloodFiller(ipEllTempOne); fEllO.fill(0,0);

Page 100: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

38  

if(imgTp == 4){ ipEllTempTwo.setColor(0); ipEllTempTwo.fillOval((int)Math.round(xCentroidSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxisSpot[lengthPts-2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxisSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth))); ipEllTempTwo.setRoi((int)Math.round(xCentroidSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[lengthPts-2]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) + 2, (int)Math.round(majAxisSpot[lengthPts-2]/((imp.getCalibration()).pixelWidth)) + 2); ipEllTempTwo.rotate(-axisAngleSpot[lengthPts-2]); ipEllTempTwo.setColor(palette[imgTp-2]); FloodFiller fEllT = new FloodFiller(ipEllTempTwo); fEllT.fill(0,0); impTempOne = icA.run("AND create", impEllTempOne, impEllTempTwo); } else{ impTempOne = impEllTempOne; imgTp--; } ipEllTempTwo.setColor(0); ipEllTempTwo.fill(); ipEllTempTwo.setColor(palette[imgTp-2]); ipEllTempTwo.fillOval((int)Math.round(xCentroidSpot[0]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[0]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(minAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth)), (int)Math.round(minAxisSpot[0]/((imp.getCalibration()).pixelWidth))); ipEllTempTwo.setRoi((int)Math.round(xCentroidSpot[0]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(yCentroidSpot[0]/((imp.getCalibration()).pixelWidth)) – (int)Math.round(majAxisSpot[0]/(2*((imp.getCalibration()).pixelWidth))), (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth)) + 1, (int)Math.round(majAxisSpot[0]/((imp.getCalibration()).pixelWidth)) + 1); ipEllTempTwo.rotate(-axisAngleSpot[0]); ipEllTempTwo.setColor(0); fEllO.fill(0,0); if(imgTp == 2) imgTp++; ImagePlus impTempTwo = icA.run("OR create", impTempOne, impEllTempTwo); impTempTwo.setTitle(nameEdited+" - colored elliptical areas"); impTempTwo.show();

Page 101: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

39  

if(nrImages== 1){ //set location of image if(100+width+30 >= dimWidth || 100+height+50 >= dimHeight) IJ.run("Out [-]", ""); impTempTwo.getWindow().setLocation(dimWidth-(100+width+30), 100); } } } } // <<-- show the resultsTable with all the data -->> String titleEdited = (imp.getTitle()).substring(0,(imp.getTitle()).lastIndexOf("."))+" - data results"; if(nrImages != 1) titleEdited = "Data results"; if(calcData != 0) rtAreas.show(titleEdited); }//end of run // <<-- method to find a white pixel from the central spot -->> public int[] findWhite(int x, int y, ImageProcessor ip, int startColor){ boolean notfound = true; int width = 2*x; //mainly for the Single Eyespot image type int height = 2*y; //mainly for the Single Eyespot image type int a = 1; int i = 1; int side = 1; //number of pixels to move forward int[] array = {0,0}; while(notfound && x < width-1 && x > 0 && y < height-1 && y > 0){ int pixel = ip.getPixel(x,y); int red = (pixel & 0x00ff0000) >> 16; int green = (pixel & 0x0000ff00) >> 8; int blue = pixel & 0x000000ff; if (red >= startColor && green >= startColor && blue >= startColor){ notfound = false; array[0] = x; array[1] = y; } else{ boolean change = true; while(change){ if(i <= 2*side){ if(i <= side){ x = x - a; } else{ y = y - a; } change = false; i++; } else{ i = 1; side++; a = a - 2*a;

Page 102: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

40  

} } } } return array; } // <<-- method to binary treat the image -->> public ImageProcessor macroWork(ImagePlus imp){ String name = imp.getTitle(); String nameEdited = name.substring(0, name.lastIndexOf(".")); int width = imp.getWidth(); int height = imp.getHeight(); ImageProcessor ipLines = new ByteProcessor(width, height); Dimension dim = IJ.getScreenSize(); int dimWidth = dim.width; int dimHeight = dim.height; int blur = 1; boolean treat = true; Duplicator duplicate = new Duplicator(); ImageProcessor ip = imp.getProcessor(); ImagePlus copy = new ImagePlus("copy of original", imp.getProcessor()); while(treat){ ImagePlus impSlices = duplicate.run(copy); IJ.run(impSlices, "HSB Stack", ""); ImageStack stack = impSlices.getStack(); ipLines = stack.getProcessor(3); ImagePlus impLines = new ImagePlus(nameEdited+" - frontiers",ipLines); IJ.run(impLines, "Gaussian Blur...", "sigma="+blur); IJ.run(impLines, "Make Binary", ""); IJ.run(impLines, "Outline", ""); IJ.run(impLines, "Skeletonize", ""); impLines.show(); if(100+width+30 <= dimWidth){ if(100+height+50 <= dimHeight){ impLines.getWindow().setLocation(100, 100); } else{ impLines.getWindow().setLocation(100, 0); } } else if(100+height+50 <= dimHeight){ impLines.getWindow().setLocation(0, 100); } else{ impLines.getWindow().setLocation(0, 0); }

Page 103: QUANTITATIVE ANALYSIS OF BICYCLUS ANYNANA‘S EYESPOT …repositorio.ul.pt/bitstream/10451/5942/1/ulfc... · imagens de microscopia de fluorescência mostrando expressão da proteina

41  

IJ.runMacro("setTool(12)"); WaitForUserDialog usr = new WaitForUserDialog("Confirm", "Check if the frontiers are closed and not merged to each\n

other or the areas aren't too small, and then click OK."); usr.show(); YesNoCancelDialog confirmTreat = new YesNoCancelDialog(IJ.getInstance(), "Confirm", "Are the frontiers well defined?\n \n

Press [No] to apply more blur.\nPress [Cancel] to enlarge the image and process it again."); if (confirmTreat.yesPressed()){ treat = false; impLines.hide(); } else if(confirmTreat.cancelPressed()){ impLines.changes = false; impLines.close(); copy.setProcessor((copy.getProcessor()).resize((size+1)*width)); size++; } else{ impLines.changes = false; impLines.close(); blur++; } } IJ.runMacro("setTool(0)"); return ipLines; } // <<-- Dialog listener for greying out -->> public boolean dialogItemChanged(GenericDialog gd, AWTEvent e){ String a = (gd.getCheckboxes().get(4-2*imgTp*(imgTp-1)*(imgTp-2)/3+imgTp*(imgTp-1)*(imgTp-2)*(imgTp-3)/2)).toString(); if((a.substring(a.length()-5,a.length()-1)).equals("true")){ ((TextField) gd.getNumericFields().get((int)(imgTp*(1+(imgTp-1)*(

(double)(imgTp-2)*(imgTp-4)/2-(double)(imgTp-3)*(imgTp-4)/4-(double)(imgTp-2)*(imgTp-3)/6))))).setEnabled(false); } else{ ((TextField) gd.getNumericFields().get((int)(imgTp*(1+(imgTp-1)*(

(double)(imgTp-2)*(imgTp-4)/2-(double)(imgTp-3)*(imgTp-4)/4-(double)(imgTp-2)*(imgTp-3)/6))))).setEnabled(true); } return true; } // <<-- method to calculate the distance between two points -->> public double distance(double x0, double y0, double x1, double y1){ double dx = x0 - x1; double dy = y0 - y1; double D = Math.sqrt( dx*dx + dy*dy ); return D; } }//End of plugin