ข้ามไปที่เนื้อหาหลัก

RANdom SAmple Consensus (RANSAC) algorithm

Introduction

fig. 1 picture from 'Multiview geometry in Computer Vision' book.

If you use orthogonal regression ( minimizes the sum of squared perpendicular distances -- LMS ), there will be a problem if you have an outliers (see fig 1a).

RANSAC algorithm

RANSAC algorithm will cope with this problem by discarding outliers.

Slide from 25th year of RANSAC, Philip Torr slides has very clear picture of the algorithm.






support = number of points that lie within a distance threshold

points within the threshold distance of a line with most support are the inliers.

If a point is an outliers, a line will not have so much support. ( see fig 1b from mvg book above )

Explain the algorithm

- First we randomly pick two red point and estimate m, c for y=mx+c ( this is easy, right )

- for consider if a point is a inlier
for every yellow point (x, y)
If | y - (m*x + c) | < t, number of inlier need to justify model

-- re-estimate m, c again by using all the inlier

sample code ?

a simple python example code for RANSAC is available here.
or more complicate code here. all is the same code as a psudocode from wiki.

or you can use my porting octave code here ( NOTE if you are using matlab, this code should be modified )

# Run RANSAC to see if we can recover the line (y=x) from the data.
function [model_params, model_error, model_inliers] = ransac(data,n,k,t,d)
  % k -- the number of iterations.
  % t -- the threshold for deciding when a data point fits a model (i.e. is an inlier).
  % d -- the number of inliers needed to justify the model.

# k=100,d=20
  model_params = [0.0, 0.0] # slope and intercept
  model_error = 1e6
  model_inliers = []

  for i=1:k # k iterations
      fprintf(1, "new iteraion\n\n")
      inliers = choice(data, n)
   
      # Fit a line (or generally any model) using lstsq.
      a = [inliers(:,1), ones(1, n)']
      b = inliers(:,2)

      # linear least square -- rewrite y = mx+c in y = A*p form
      # A = [x 1]      
      # p = [m, c]
      p = a \ b
    
      compatible = []
      for j=1:size(data, 1)
          fprintf(1, '--')
          pt = data(j,:)
          if abs(pt(2) - dot(p, [pt(1), 1.0])) < t # | y - (m*x + c) | < t
              compatible = [compatible; pt]
          end  
      end  

      if size(compatible, 1) > d
          # The current model is good enough so we should recompute it using all compatible points.
          a = [compatible(:,1), ones(1, size(compatible, 1))']
          b = compatible(:,2)
          p = a \ b
       
          # if residuals < model_error
              model_params = p
              # model_error = residuals
              model_inliers = compatible
          # end
      end
  end

function result=choice(seq, n)
  indx = 1:size(seq)-1
  shuffle(indx)
  result = seq(indx(1:n), :)


adaptively find k (the number of iterations)
k = log(1-p)/log(1-(1-ε)^n)

proof ( ref : wiki ) :

p
= prob(RANSAC algorithm in some iteration selects only inliers )

w = prob( choosing an inlier each time a single point is selected ) = number of inliers / number of all points

A common case is that w is not well known beforehand, but some rough value can be given.

n = Sample Size

wn = prob( n points are inliers )
1 − wn = prob( at least one of the n points is an outlier ) [ bad model will be estimated from this point set ]
( 1 − wn k = prob( algorithm never selects a set of n points which all are inliers )
( 1 − wn )k = 1 − p
take log and we will get
k = log(1-p)/log(1-w^n)

It should be noted that this result assumes that the n data points are selected independently, that is, a point which has been selected once is replaced and can be selected again in the same iteration.

Apply to Homography
When adapt this to Homography, estimating line is not a visual line. The error is computing from transfer error d.

This RANSAC for Homography steps are adapt from Alexei (Alyosha) Efros's slide.

RANSAC loop:
1. Select 4 feature pairs (at random)
[ n in the code, or s in the book is fixed to 4 ]
2. Compute homography H (exact)
3. If d(x’, H x) largest set of inliers
[ so the number of inliers needed to justify the model ( d in the code or capital T in the book ) is not used here. ]
5. Re-compute least-squares H estimate on all of the inliers

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งไปรษณีย์ทีละมากๆ ที่ช่องไปรษณีย์สำหรับธุรกิจ

  ถ้าเราส่งไปรษณีย์ทีละ 10 กล่องขึ้นไป สามารถไปส่งโดยใช้ช่องทางธุรกิจได้ โดยต้องกรอกใบรับฝากรวม ( Receipt for bulk Posting ) เป็นลิสต์รายการให้เขาไปด้วย โดยกรอกพัสดุแต่ละรายการ และ ไปยื่นให้เขาพร้อมกับพัสดุที่จะส่ง วิธีกรอก คือ ให้กรอกพัสดุแบบเดียวกันไว้แผ่นเดียวกัน  เช่น พัสดุ10 กล่อง กล่องขนาดเท่ากัน น้ำหนักเท่ากันหมด กรอกไว้ 1 แผ่น ถ้าน้ำหนักต่างกัน ขนาดกล่องต่างกัน กรอกแยกแผ่นไว้ดีที่สุด ซึ่งใบนี้สามารถไปขอได้ที่ไปรษณีย์ฝ่ายธุรกิจ สามารถนำมาทำใส่ A4 ก็ได้ ขอบคุณคุณพี่ amarin.ch ที่ไปรษณีย์กลาง ( BANGKOK G.P.O. ) มากๆ นะครับ สำหรับคำแนะนำ ขอบคุณที่ช่วยคีย์ให้ทีละรายการสำหรับมือใหม่ที่ยังไม่รู้ว่ามีใบรับฝากรวมอย่างผมด้วยครับ คราวหน้าผมจะทำใบรับฝากรวมไปครับ

อยู่เหงาๆ เราไปเที่ยว - ไหว้พระขอพร ศาลเจ้าแม่ทับทิม (อาม่า), เจริญกรุง, กรุงเทพ; 天后聖母廟, 石龙軍路, 曼谷, 泰国; Thap Thim Chinese Goddess Shrine, Chareon Krung 63 Road, Bangkok, Thailand

天后聖母廟, 石龙軍路, 曼谷, 泰国 ไหว้ศาลเจ้าแม่ทับทิม ขอให้การค้าเจริญรุ่งเรือง ตำนานเจ้าแม่ทับทิมเกิดที่ตำบลตุ้ยบ๊วย เขตบ่นเซียว เกาะไหหลำ มีผู้เฒ่าแซ่พัว เป็นผู้มีความซื่อสัตย์สุจริต ทำงานขยันขันแข็ง ครั้งหนึ่งแกออกไปหาปลา โดยผูกแหเป็นช้อนดักปลา เวลาผ่านไปแกยังหาปลาไม่ได้ คืนนั้นก็ประสบความล้มเหลว เมื่อช้อนแหขึ้นมาทีไรก้อมีแต่ท่อนไม้ ด้วยความโมโหแกเลยขว้างท่อนไม้นั้นออกไปให้ไกล แต่แล้วเมื่อช้อนแหขึ้นมาใหม่ก็ปรากฏท่อนไม้ท่อนเดิมอีก ต่อจากนั้นแกก็ขว้างท่อนไม้ขึ้นฝั่ง และแกก็ฉุก คิดว่าแปลกที่ท่อนไม้ธรรมดาจะสามารถลอยทวนน้ำได้ คงจะเป็นสิ่งวิเศษ และแกก็ได้นำท่อนไม้นั้นขึ้นฝั่ง และเพ่งมองท่อนไม้นั้นพร้อมกับอธิษฐานว่า หากท่อนไม้นี้มีความศักดิ์สิทธิ์ขอให้คืนนี้จับปลาได้มาก เมื่อพ้นจากความจนแล้ว เมื่อขึ้นฝั่งจะนำท่อนไม้นี้แกะสลักเป็นเทวรูปศักดิ์สิทธิและสักการะบูชาเช้าวันไม่ให้ขาด เมื่ออธิษฐานจบแกเอาท่อนไม้นั้นวางบนหัวเรือ ปรากฏว่าช้อนเพียงสองถึงสามครั้งก็ได้ปลาตัวโตเต็มเรือ จึงนำปลาขึ้นฝั่งวันนั้นปลาของแกขายได้ราคา เพราะชาวประมงคนอื่นจับได้น้อยแกจึงมีเงินจับจ่ายใช้สอย และทุกครั้งที่แกออกหาปลา ...

[ AI ] IBM granite, NVIDIA robotics, IBM Langflow, watsonx, LMCache, LiteRT, Self driving car, Mamba model, RAG

 IBM granite: Time series from sensor, stock market * Forcast * Anomaly detection - classification high medium risk, data synthesis Embedding AI - 1M params - edge device - small AI Send insight --- NVIDIA * Jackson Thor robotic * Nemo ---- * IBM Langflow : open source * Watsonx (n8n) Enterprise : guardrails / log, tool using policy ----- LMcache : open source KC cache Prompt -> key value (RAGs) Same context ( e.g. same docs) Reduce operating costs CacheGen : make cache cheap to move and store CacheBlend : reuse chunk, not just prefix ---- Google มี framework ที่ optimize AI บน mobile phone นั่นคือ LiteRT : google pytorch Quantisation เท่าไหร่บน device นี้ Model explorer: quantize แล้ว error < 5% XMNpack ใช้ CPU ลดลง Google AI edge portal : benchmark AI on real device ---- Self driving car * Nvidia Alpamayo 2 model * Carla simulation Random forest -> multiple scenarios -> json -> LLM Car talk to mobile phone (cross the road) ----- Mamba model (recursive)  - alte...

วิธีการไป อย. กระทรวงสาธารณสุขจากหัวลำโพง

ทางไป : รถไฟฟ้า MRT หัวลำโพง ไปลงที่ สถานี กระทรวงสาธารณสุข  ถ้ากดที่ตู้ต้องเปลี่ยนไปหน้าจอสายสีม่วง สนน ราคา 48 53 บาท ต่อมอไซด์ ถ้าไป อย. 20 บาท จากหน้าทางเข้า  ถ้าฝนตกแนะนำให้โบกแท็กซี่จากข้างหน้า ข้างในหาแท็กซี่ยากมาก ถ้าจะเดินประมาณ 2.4 km ให้ระวังหลงเข้าไปรพ ศรีธัญญา รพ ศรีธัญญาพื้นที่ข้างในใหญ่มาก และเหมือนจะล้อมด้วยคลอง เหมือนจะมีทางออกแค่ทางที่เข้าไปนั่นแหละ ทางกลับ : รถเมล์ 97 จาก อย. ตรงข้ามประกันสังคม ทางที่ 1 : ถ้าจะใกล้ลงหน้าปากซอยขึ้นสายสีม่วงที่สถานีกระทรวงสาธารณสุขที่เดิม ทางที่ 2 : ผ่าน ท่าน้ำนนท์​ กลับเรือได้ ทางที่ 3 : ผ่านหน้าพระจอมพระนครเหนือด้วยนะ ผ่าน สถานีรถไฟฟ้า MRT บางซื่อ  ( จาก อย. ไป MRT บางซื่อ 17 บาท,  จาก MRT บางซื่อ ไป MRT หัวลำโพง 44 บาท นั่งกลับได้ 2 ทาง ทางหัวลำโพง กับ ไปเปลี่ยนที่ท่าพระ ไม่รู้ว่าทางไหนเร็วกว่ากัน ) ทางที่ 4 :  ผ่าน สะพานควาย  ทางที่ 5 :  นั่งถึงอนุสาวรีย์ชัยสมรภูมิได้ ค่ารถเมล์ 21 บาท ค่ารถไฟฟ้าไป BTS สะพานตากสิน 47 บาท 

EJB development ด้วย Glassfish Server -- Part 2 ( Create a project )

สร้าง project สำหรับ EJB module สร้าง EJB project ชื่อว่า titan-ejb เลือก Target Runtime : Glassfish คลิกขวาที่ Project ติ๊ก JPA facet, และ configure JPA facet ให้ใช้ connection profile ที่สร้างไว้แล้ว >>>>>>>>>>>>>>>>>>> วิธีสร้าง JPA Entity: - คลิกขวาที่ Project Explorer - New->Class ชื่อ com.titan.domain.Cabin implement java.io.Serializable [ Serializable คือ สามารถ convert class to String แล้วส่งไปที่ network ได้ ] วิธีสร้าง implement class บน eclipse มันก็จะสร้างฟังก์ชั่นโบ๋ๆ มาให้ package com.titan.domain; import java.io.Serializable; public class Cabin implements Serializable { } - Add the fields static final long serialVersionUID = 1L; private int id; private String name; private int deckLevel; private int shipId; private int bedCount; - สร้าง getters and setters สำหรับ id, name, deckLevel, shipId, and bedCount. [ ใน eclipse ง่ายมาก ไปที่ Source > Generate setters and getters ( หรือ คลิกขวาตรงที่เขียนโค้ด So...

เฉินหลงฟัดในปี 2025 The Shadow's Edge

เริ่มดูเพราะ ฉากในลิฟต์ ที่เด้งมาใน tiktok เลยรู้สึกว่า หนังดูมีอะไรจังวะ  พอดูจริงๆ หนังมีอะไรอย่างที่คิดไว้ แม้ตอนแรกๆ ตอนปล้น อาจจะให้ความรู้สึกเหมือน Now You See Me ไปบ้าง แต่หนังมีความสนุก มีอารมณ์ความรู้สึก  มีการใส่เทคโนโลยีใหม่ๆ อย่าง เทคโนโลยีคล้ายๆกับของ Peter Theil แต่ก็ทำงานร่วมกับคนรุ่นเก่าอย่างเฉินหลงได้อย่างดี มีการสร้างตัวร้ายที่เก่งสมน้ำสมเนื้อ  และ ทิ้งท้ายว่า จะมีภาคต่ออีกต่างหาก ชอบประโยคที่ว่า "นายต้องจบงานเองได้"

รีวิว: Human Resource พนักงานใหม่โปรดรับไว้พิจารณา สปอยแหลก

a.k.a. ชนแม่งเลย หนังเป็น พี่เต๋อ ที่พร้อมจะหักมุมตลอดเวลา คาดเดาอะไรไม่ได้เลย หนังที่คิดว่าเป็นหนังคนทำงาน ดันมีฉาก เรท R มาเฉย ได้ข้อคิด แต่ไม่ได้ชอบมาก เพราะ ประเทศที่พัฒนาแล้วจะไม่มาคิดเรื่องพวกนี้เลยสักนิด  ถ้าตอนนี้ไปดูประเทศสหรัฐ (ที่กำลังบูมเรื่อง AI) ประเทศจีน (ตามมาติดๆ หรือนำไปแล้ว?) ประเทศ ไต้หวัน (ที่กำลังบูมเรื่อง เซมิคอนดักเตอร์) ประเทศเกาหลี (แซมซัง ก็ไล่มาติดๆ) ประเทศเวียดนาม (ที่ต่างชาติไปลงทุนมากๆ) จะไม่มีคำถามอะไรพวกนี้ในสมองเลย ลองไปฟังวิทยุช่องจีน ในเมืองที่เจริญๆ เมืองเศรษฐกิจ จะมีแต่ภาพ อนาคต ความหวัง ของใหม่ โรงงานใหม่ วิธีทำงานแบบใหม่ positive กว่ามาก ถ้ามัวแต่คิดเหมือนที่หนังปูในตอนแรก จะทำให้เรา ตกอยู่ใน loop นรก ซึ่งยิ่งคิดยิ่งแย่ แย่จนไม่คิดจะลงมือทำอะไรเลย เพราะจิตเป็นนายกายเป็นบ่าว สื่อ อย่าไปออกเรื่องไม่ดีมาก ออกเรื่องดีๆบ้าง เดี๋ยวคนในประเทศหวาดกลัวจนไม่กล้าทำอะไร ถึงตอนนั้นก็แย่ของจริง ตอนนี้คนประเทศอื่น ทำหนังลง Netflix กันเยอะนะครับ มีหนังใหม่ๆ ของประเทศอื่นเต็มไปหมด เช่น ฝรั่งเศส เยอรมัน สหรัฐ เกาหลี  บางอันก็ดัง บางอันก็ไม่รู้จัก 

แนะนำ ยาบำรุงครรภ์ จับซาไท้เป้า หรือ 13 องครักษ์พิทักษ์ครรภ์ ยาจีน บำรุงครรภ์

จับซาไท้เป้า  ยาบำรุงครรภ์ สมุนไพรจีน ช่วงนี้เพื่อนๆ เริ่ม ทยอย แต่งงาน กันแล้ว นะครับ เราเองก็มียาจีนมา นำเสนอ ซึ่งเป็น ยาดี ที่คุณแม่ ของเรา ทาน ตอนคลอดเรา นั่นก็คือ "จับซาไท้เป้า" ยาบำรุงครรภ์ นั่นเอง เงง เงง เงง เงง จับซาไท้เป้า เป็น ยาจีน ซึ่ง ประกอบไปด้วย สมุนไพร จีน 13 อย่างด้วยกัน มี สรรพคุณ เป็น ยาบำรุงครรภ์ บำรุง ทั้งคุณแม่ และ คุณลูก เลย เรียกได้ว่า สรรพคุณ ครบครัน บำรุง คุณแม่ ช่วงตั้งท้อง ช่วยให้ คุณลูก แข็งแรง มีผิวพรรณ สะอาดสะอ้าน ในตอนที่คลอดออกมา จะ คลอดง่าย ตัวจะไม่มีคราบไขมันติดเยอะ จ้า วิธีกินจับซาไท้เป้า ทานตั้งแต่ท้อง 5 เดือนขึ้นไป 2 อาทิตย์ทาน 1 ห่อ ทานจนคลอด ศิริรวมแล้ว ถ้าทาน ครบ dose โดยเริ่มตั้งแต่ 5 เดือน ต้องทานทั้งหมด 10 ห่อ จ้ะ วิธีต้มจับซาไท้เป้า  1 ห่อ ต้มได้ 2 ครั้ง ครั้งแรก ใส่น้ำ 3 ถ้วย ต้มเหลือ 8/10 ถ้วย ครั้งที่ 2 ใส่น้ำ 2.5 ถ้วย ต้มเหลือ 7/10 ถ้วย ซื้อที่ไหนดี หลายๆ คน มักจะมีคำถาม ว่า จับซาไท้เป้า ซื้อที่ไหน  ซึ่งเราเอง แนะนำร้านขาย จับซาไท้เป้า ซึ่งก็คือ ร้าน ขายยา ย่ง เช...

กระแส AI อุตสาหกรรมอะไรดีบ้าง

กระแส AI Super Cycle ไม่ได้ส่งผลดีแค่กับคนทำซอฟต์แวร์ แต่กำลัง "ยกแผง" อุตสาหกรรมโครงสร้างพื้นฐาน (Infrastructure) ทั้งหมด โดยเฉพาะ 3 กลุ่มหลัก ดังนี้ครับ: 1. อุตสาหกรรมพลังงาน (Energy & Utilities) AI คือ "จอมเขมือบไฟ" ทำให้บริษัทที่ทำระบบผลิตไฟฟ้าและจัดการพลังงานกลายเป็นพระเอกใหม่ โดยเปลี่ยนจากพลังงานแบบเดิมมาเป็นเทคโนโลยีที่สะอาดและเสถียรมากขึ้น สิ่งที่ดีขึ้น: มีการนำเทคโนโลยี Fuel Cell มาใช้ผลิตไฟฟ้าโดยไม่ผ่านการเผาไหม้ เพื่อตอบโจทย์ Data Center ที่ต้องรัน 24 ชม. ตัวอย่าง: Bloom Energy (BE): ใช้ระบบ Solid-oxide Fuel Cell เปลี่ยนก๊าซเป็นไฟฟ้าให้ Oracle แบบ 100% ในโปรเจกต์ยักษ์ Delta Electronics: กลายเป็นตัวตึงด้านระบบจัดการพลังงานที่กำไรทุบสถิติประวัติศาสตร์ 2. อุตสาหกรรมฮาร์ดแวร์และเซมิคอนดักเตอร์ (Hardware & Supply Chain) เมื่อ AI ต้องประมวลผลมหาศาล อุปกรณ์เบื้องหลังจึงต้อง "อัปเกรด" ขนานใหญ่ จนเกิดสภาวะ "คนขายเป็นใหญ่" (Seller's Market) สิ่งที่ดีขึ้น: ความต้องการชิ้นส่วนเฉพาะทางพุ่งสูงขึ้นอย่างก้าวกระโดด ทั้งแผ่นรองชิป, หน่...

Dataset พระไตรปิฎก เผื่อพวกท่านเอาไปสร้าง หลวงพรี่ AI

* พระไตรปิฎกภาษาไทยฉบับสยามรัฏฐ จำนวน 45 เล่ม https://huggingface.co/datasets/uisp/tripitaka-siamrath * พระไตรปิฎกและอรรถกถาไทยฉบับมหามกุฏราชวิทยาลัย จำนวน 91 เล่ม https://huggingface.co/datasets/uisp/tripitaka-mbu