แสดงบทความที่มีป้ายกำกับ frequency domain แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ frequency domain แสดงบทความทั้งหมด

วันพฤหัสบดีที่ 20 เมษายน พ.ศ. 2560

FD Math การแปลงภาพโดยการประมวผลทางคณิตศาตร์ ระหว่างภาพ 2 ภาพ

FD Math…


เป็นคำสั่งเกี่ยวกับ correlates, convolves, deconvolves ของภาพ 2 ภาพ

It does this by converting Image1 and Image2 to the frequency
domain, performing conjugate multiplication or
division, then converting the result back to the space domain.
These three operations in the frequency domain are
equivalent to correlation, convolution and deconvolution in
the space domain.


วิธีการ คือการแปลงภาพ Image1 และ Image2 ให้อยู่ในรูปแบบของ frequency domain เพื่อประสิทธิภาพของการใช้การประมวลผล conjugate, multiplicaiton หรือ division  หลังจากนั้นก็จะแปลงผลลัพธ์กลับเป็น space domain การใช้ operation เหล่านี้ก็คือการประมวลผลแบบ frequency domain ซึ่งเท่ากับการประมวลผล correlation, convolution และ deconvolution ในโดเมนแบบเดิม (space domain)

สามารถดูตัวอย่างได้จากมาโคร (Macro) ดังต่อไปนี้
http://imagej.nih.gov/ij/macros/DeconvolutionDemo.txt  แสดงตัวอย่างได้ดังนี้

// This macro demonstrates the use of frequency domain convolution
// and deconvolution. It opens a samples image, creates a point spread
// function (PSF), adds some noise (*), blurs the image by convolving it
// with the PSF, then de-blurs it by deconvolving it with the same PSF.
//
// * Why add noise? - Robert Dougherty
// Regarding adding noise to the PSF, deconvolution works by
// dividing by the PSF in the frequency domain.  A Gaussian
// function is very smooth, so its Fourier, (um, Hartley)
// components decrease rapildy as the frequency increases.  (A
// Gaussian is special in that its transform is also a
// Gaussian.)  The highest frequency components are nearly zero.
// When FD Math divides by these nearly-zero components, noise
// amplification occurs.  The noise added to the PSF has more
// or less uniform spectral content, so the high frequency
// components of the modified PSF are no longer near zero,
// unless it is an unlikely accident.
  if (!isOpen("bridge.gif")) run("Bridge (174K)");
  if (isOpen("PSF")) {selectImage("PSF"); close();}
  if (isOpen("Blurred")) {selectImage("Blurred"); close();}
  if (isOpen("Deblurred")) {selectImage("Deblurred"); close();}
  newImage("PSF", "8-bit black", 512, 512, 1);
  makeOval(246, 246, 20, 20);
  setColor(255);
  fill();
  run("Select None");
  run("Gaussian Blur...", "radius=8");
  run("Add Specified Noise...", "standard=2");
  run("FD Math...", "image1=bridge.gif operation=Convolve image2=PSF result=Blurred do");
  run("FD Math...", "image1=Blurred operation=Deconvolve image2=PSF result=Deblurred do”);

และ http://imagej.nih.gov/ij/macros/MotionBlurRemoval.txt  แสดงคำสั่งได้ดังนี้
  // Demonstrates motion blur removal using deconvolution.
  // For more information, do a Google search for "FFT motion blur".
  // open the "bridge" sample image
  run("Bridge (174K)");
  // Create a line-shaped point source function
  newImage("PSF", "8-bit black", 512, 512, 1);
  setForegroundColor(255, 255, 255);
  makeLine(251, 251, 261, 261);
  run("Draw");
  run("Select None");
  // Convolve Bridge with PSF to generate motion blurred image
  run("FD Math...", "image1=bridge.gif operation=Convolve image2=PSF result='Motion Blurred' do");
  // Deconvolve motion blurred image with PSF to generate deblurred image
  run("FD Math...", "image1='Motion Blurred' operation=Deconvolve image2=PSF result=Deblurred do");

ตัวอย่าง




ภาพ 2 ภาพที่จะนำมาประมวลผล ต้องมีขนาดเท่ากัน


การเลือกเมนู


ผลลัพธ์

Operation = Correlate



Operation = Convolve




Operation = Deconvolve



การแปลงกลับของ FFT (Inverse FFT)

Inverse FFT

การคำนวณย้อนกลับของ Fourier transform โดยเราสามารถสร้างจุดบนภาพที่ถูกแปลงแบบ  frequency domain ก็ได้ และหลังจากกำหนดจุดบนภาพแล้วสามารถแปลงกลับโดยใช่ส่วนประกอบระหว่าง frequency domain ร่วมกับจุดภาพที่สร้างขึ้นใหม่ก็จะได้ผลลัพธ์ภาพอีกแบบ

สามารถใช้เครื่องมือ selection tools  สำหรับการ fill/clear ในการวาดจุดสีขาว หรือ สีดำ โดยการกำนดจุดที่ต้องการเปลี่ยนแปลง พื้นที่สีดำ คือว่า pixel = 0 โดยการแปลงภาพแบบนี้จะเป็นเป็นการเปรียบเทียบและ filtered ค่า pixel ที่สอดคล้องกันเพื่อการลบออก  ส่วนการกำหนดเป็นสีขาว ค่า pixel=255 ส่วนนี้จะเป็นการเปรียบเทียบความสอดคล้องกันที่จะปล่อยผ่าน แต่อย่างไรก็ตามทั้งสองแบบนี้ก็เกิดจากการวิธีการ inverse แบบเดียวกัน

หมายเหตุ พื้นที่วงกลมที่วาดบนภาพแบบ frequency domain ถ้าเติมแบบ zero จะได้ค่าเป็นค่า 0 และถ้าเติมค่าแบบ passed ผลที่ได้จะเป็นค่า 255  ตรวจสอบค่าได้ด้วยการลากเส้นผ่านตำแหน่งที่เติมค่าลงไป โดยค่าแสดงที่แถบสถานะของโปรแกรม เป็น 0 หรือ 255 ดังนั้น การเติมค่าสีต้องมั่นใจว่าค่าจะผิดเพี้ยนกลายเป็นค่าระดับเทา ด้วยการเปลี่ยนแปลงค่าที่หน้าต่าง Color Picker window เมื่อกำหนดค่าสี foreground (Edit->Fill [f]) และ ค่า background (Edit->Clear)

หากการเลือกไม่ได้อยู่ตรงกลางของภาพ ตำแหน่งที่กำหนดตำแหน่งจุดพื้นที่ลงไปจะเกิดขึ้นสองฝั่งและอยู่ตรงข้ามกัน (เทียบกับจุดศูนย์กลาง) ในกรณีแบบนี้ทำให้เราสามารถกำหนดจุดพื้นที่ zero หรือ passed เพียงด้านเดียวก็เพียงพอ โดยไม่ต้องกำหนดทุกจุดพื้นที่ ที่อยู่ตรงข้ามกัน (กรณีไม่ได้กำหนดจุดพื้นที่อยู่ตรงกลาง)

ตัวอย่าง
จากภาพปกติ



ต้องแปลงให้เป็น frequency domain



ทำการวาดจุดทั้งสีดำ และ สีขาว





การเลือกเมนู



ผลลัพธ์

จากจุดสีดำ





จากจุดสีขาว




การแปลงภาพแบบ FFT

FFT

ประมวลผลภาพ ด้วยอัลกอริทึมแบบ Fourier transform พร้อมด้วยความสามารถในการแสดงข้อมูลแบบแถบสี (power spectrum) ข้อมูลแบบพิกัดโพลา (polar coordinates) ซึ่งสามารถแสดงได้จากการจุดที่เลือก และดูข้อมูลเพิ่มเติมรายละเอียดข้อมูลที่เกี่ยวข้องได้ที่ Analyze->Measure...[m]


การประมวลผล สำหรับ FFT

ถ้าเมาส์เลื่อนผ่านหน้าต่าง FFT ตำแหน่งจะแสดงในส่วนของพิกัดแบบโพลา โดยมุมจะแสดงด้วยองศา ขณะที่รัศมีจะแสดงในสัดส่วนของพิกเซลต่อรอบ (p/c) หน่วยของรัศมีใช้หน่วย ต่อรอบ (ตัวอย่าง เช่น mm/c) สำหรับต้องการหน่วยอื่น ๆ สามารถกำหนดเพิ่มเติมได้ที่เมนู Image->Properties...[P] หรือ Analyze->Set Scale...

ตัวอย่างการคำนวณ FFT



การเลือกเมนู



ผลลัพธ์